From 53e568efe6f2a9e121ac6cf305e5fa9a84137c1a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 3 Jan 2013 22:11:27 +0000 Subject: - fix for the buffer overrun in YAMN's mime parser - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@2948 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/YAMN/src/browser/mailbrowser.cpp | 43 +++++++++++++------------ plugins/YAMN/src/mails/decode.cpp | 8 ++--- plugins/YAMN/src/mails/mails.cpp | 4 +-- plugins/YAMN/src/mails/mime.cpp | 55 ++++++++++++++++---------------- plugins/YAMN/src/main.cpp | 4 +-- plugins/YAMN/src/proto/netlib.cpp | 2 +- plugins/YAMN/src/proto/pop3/pop3.cpp | 2 +- plugins/YAMN/src/proto/pop3/pop3comm.cpp | 13 ++++---- plugins/YAMN/src/services.cpp | 14 ++++---- plugins/YAMN/src/yamn.cpp | 6 ++-- 10 files changed, 77 insertions(+), 74 deletions(-) (limited to 'plugins/YAMN') diff --git a/plugins/YAMN/src/browser/mailbrowser.cpp b/plugins/YAMN/src/browser/mailbrowser.cpp index 4f1f5593d6..be88c467d3 100644 --- a/plugins/YAMN/src/browser/mailbrowser.cpp +++ b/plugins/YAMN/src/browser/mailbrowser.cpp @@ -847,7 +847,7 @@ LRESULT CALLBACK NewMailPopUpProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam { HANDLE hContact = 0; HACCOUNT Account; - if (PluginParam){ + if (PluginParam) { PYAMN_MAILSHOWPARAM MailParam = new YAMN_MAILSHOWPARAM; memcpy(MailParam,(PINT_PTR)PluginParam,sizeof(YAMN_MAILSHOWPARAM)); hContact = MailParam->account->hContact; @@ -1084,7 +1084,7 @@ ULONGLONG MimeDateToFileTime(char *datein) //datein = " ManySpaces 1.5 Jan 2060 05::"; //datein = "Xxx, 35 February 20 :29:10 "; //datein = "01.12.2007 (22:38:17)"; // - if (datein){ + if (datein) { char tmp [64]; while ( datein[0]==' ') datein++; // eat leading spaces strncpy(tmp,datein,63); tmp [63]=0; @@ -1092,14 +1092,14 @@ ULONGLONG MimeDateToFileTime(char *datein) day = tmp; } else { int i = 0; - while (tmp[i]==' ')i++; if (day = strchr(&tmp[i],' ')){day[0]=0; day++;} + while (tmp[i]==' ')i++; if (day = strchr(&tmp[i],' ')) {day[0]=0; day++;} } - if (day) {while ( day[0]==' ') day++;if (month= strchr(day, ' ')){month[0]=0; month++;}} + if (day) {while ( day[0]==' ') day++;if (month= strchr(day, ' ')) {month[0]=0; month++;}} if (month) {while (month[0]==' ')month++;if (year = strchr(month,' ')) { year[0]=0; year++;}} - if (year) {while ( year[0]==' ') year++;if (time = strchr(year, ' ')) { time[0]=0; time++;}} - if (time) {while ( time[0]==' ') time++;if (shift= strchr(time, ' ')){shift[0]=0; shift++;shift[5]=0;}} + if (year) {while ( year[0]==' ') year++;if (time = strchr(year, ' ')) { time[0]=0; time++;}} + if (time) {while ( time[0]==' ') time++;if (shift= strchr(time, ' ')) {shift[0]=0; shift++;shift[5]=0;}} - if (year){ + if (year) { st.wYear = atoi(year); if (strlen(year)<4) if (st.wYear<70)st.wYear += 2000; else st.wYear += 1900; }; @@ -1110,14 +1110,14 @@ ULONGLONG MimeDateToFileTime(char *datein) h = time; if (m = strchr(h,':')) { m[0]=0; m++; - if (s = strchr(m,':')){s[0] = 0; s++;} + if (s = strchr(m,':')) {s[0] = 0; s++;} } else s=0; st.wHour = atoi(h); st.wMinute = m?atoi(m):0; st.wSecond = s?atoi(s):0; } else {st.wHour=st.wMinute=st.wSecond=0;} - if (shift){ + if (shift) { if (strlen(shift)<4) { //has only hour wShiftSeconds = (atoi(shift))*3600; @@ -1141,7 +1141,8 @@ ULONGLONG MimeDateToFileTime(char *datein) return res; } -void FileTimeToLocalizedDateTime(LONGLONG filetime, WCHAR *dateout, int lendateout){ +void FileTimeToLocalizedDateTime(LONGLONG filetime, WCHAR *dateout, int lendateout) +{ int localeID = CallService(MS_LANGPACK_GETLOCALE,0,0); //int localeID = MAKELCID(LANG_URDU, SORT_DEFAULT); if (localeID==CALLSERVICE_NOTFOUND) localeID=LOCALE_USER_DEFAULT; @@ -1154,7 +1155,7 @@ void FileTimeToLocalizedDateTime(LONGLONG filetime, WCHAR *dateout, int lendateo WORD wTodayYear, wTodayMonth, wTodayDay; FILETIME ft; BOOL willShowDate = !(optDateTime&SHOWDATENOTODAY); - if (!willShowDate){ + if (!willShowDate) { GetLocalTime(&st); wTodayYear = st.wYear; wTodayMonth = st.wMonth; @@ -1174,7 +1175,7 @@ void FileTimeToLocalizedDateTime(LONGLONG filetime, WCHAR *dateout, int lendateo dateout[lendateout-1]=0; int templen = 0; if (!willShowDate) willShowDate = (wTodayYear!=st.wYear)||(wTodayMonth!=st.wMonth)||(wTodayDay!=st.wDay); - if (willShowDate){ + if (willShowDate) { templen = GetDateFormatW(localeID,(optDateTime&SHOWDATELONG)?DATE_LONGDATE:DATE_SHORTDATE,&st,NULL,dateout,lendateout-2); dateout[templen-1] = ' '; } @@ -1396,7 +1397,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM } //if (!hasBody) if (!strcmp(Header->name,"Body")) hasBody = true; int count = 0; WCHAR **split=0; - if (str2){ + if (str2) { int ofs = 0; while (str2[ofs]) { if ((str2[ofs]==0x266A)||(str2[ofs]==0x25D9)||(str2[ofs]==0x25CB)|| @@ -1440,12 +1441,12 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM if (str1) free(str1); if (str2) free(str2); } - if (body){ + if (body) { WCHAR *bodyDecoded = 0; char *localBody=0; if (contentType) { if (!_strnicmp(contentType,"text",4)) { - if (transEncoding){ + if (transEncoding) { if (!_stricmp(transEncoding,"base64")) { int size = (int)strlen(body)*3/4+5; localBody = new char[size+1]; @@ -1475,7 +1476,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM MailParam->mail->Flags |= YAMN_MSG_BODYREQUESTED; CallService(MS_YAMN_ACCOUNTCHECK,(WPARAM)MailParam->account,0); } else { - if (MailParam->mail->Flags & YAMN_MSG_UNSEEN){ + if (MailParam->mail->Flags & YAMN_MSG_UNSEEN) { MailParam->mail->Flags&=~YAMN_MSG_UNSEEN; //mark the message as seen HWND hMailBrowser; if (hMailBrowser=WindowList_Find(YAMNVar.NewMailAccountWnd,MailParam->account)) { @@ -1580,7 +1581,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM MoveWindow(GetDlgItem(hDlg,IDC_SPLITTER),5,localSplitPos,HeadSizeX-10,2,TRUE); MoveWindow(hEdit,5,localSplitPos+6,HeadSizeX-10,HeadSizeY-localSplitPos-11,TRUE); //where to put text window while resizing MoveWindow(hList, 5 ,5 ,HeadSizeX-10 ,(isBodyShown?localSplitPos:HeadSizeY)-10,TRUE); //where to put headers list window while resizing - //if (changeX){ + //if (changeX) { if (GetClientRect(hList,&coord)) { localSizeX=coord.right-coord.left; } else localSizeX=HeadSizeX; @@ -1607,7 +1608,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel")); int nReturnCmd = TrackPopupMenu( hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hDlg, NULL ); DestroyMenu( hMenu ); - if (nReturnCmd>0){ + if (nReturnCmd>0) { int courRow=0; size_t sizeNeeded = 0; TCHAR headname[64]={0}, headvalue[256]={0}; @@ -1647,7 +1648,7 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM return 0; } -DWORD WINAPI ShowEmailThread(LPVOID Param){ +DWORD WINAPI ShowEmailThread(LPVOID Param) { struct MailShowMsgWinParam MyParam; MyParam=*(struct MailShowMsgWinParam *)Param; @@ -1656,7 +1657,7 @@ DWORD WINAPI ShowEmailThread(LPVOID Param){ #endif SCIncFcn(MyParam.account->UsingThreads); SetEvent(MyParam.ThreadRunningEV); - if (MyParam.mail->MsgWindow){ + if (MyParam.mail->MsgWindow) { //if (!BringWindowToTop(MyParam.mail->MsgWindow)) { if (!SetForegroundWindow(MyParam.mail->MsgWindow)) { SendMessage(MyParam.mail->MsgWindow,WM_DESTROY,0,0); @@ -2401,7 +2402,7 @@ INT_PTR CALLBACK DlgProcYAMNMailBrowser(HWND hDlg,UINT msg,WPARAM wParam,LPARAM AppendMenu(hMenu, MF_STRING, (UINT_PTR)0, TranslateT("Cancel")); int nReturnCmd = TrackPopupMenu( hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hDlg, NULL ); DestroyMenu( hMenu ); - if (nReturnCmd>0){ + if (nReturnCmd>0) { int courRow=0; size_t sizeNeeded = 0; TCHAR from[128]={0}, subject[256]={0}, size[16]={0}, date[64]={0}; diff --git a/plugins/YAMN/src/mails/decode.cpp b/plugins/YAMN/src/mails/decode.cpp index 867ed7ff25..3af1edc056 100644 --- a/plugins/YAMN/src/mails/decode.cpp +++ b/plugins/YAMN/src/mails/decode.cpp @@ -303,13 +303,13 @@ int DecodeQuotedPrintable(char *Src,char *Dst,int DstLen, BOOL isQ) for (int Counter=0;((char)*Src!=0) && DstLen && (Counter++MailFcn!=NULL){ + if (Plugin->MailFcn!=NULL) { if (Plugin->MailFcn->DeleteMailFcnPtr!=NULL) { //Let plugin delete its own CMimeMsgQueue derived structure Plugin->MailFcn->DeleteMailFcnPtr(OldMail); @@ -435,7 +435,7 @@ void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head) while (!DOTLINE(finder+1))finder++; if (ENDLINE(finder))finder--; prev2 = finder; - if (prev2>prev1){ // yes, we have body + if (prev2>prev1) { // yes, we have body if (NULL==(Item->Next=new struct CMimeItem)) break; // Cant create new item?! Item=Item->Next; Item->Next=NULL;//just in case; diff --git a/plugins/YAMN/src/mails/mime.cpp b/plugins/YAMN/src/mails/mime.cpp index 2a66b80e2b..7b00979cad 100644 --- a/plugins/YAMN/src/mails/mime.cpp +++ b/plugins/YAMN/src/mails/mime.cpp @@ -201,7 +201,7 @@ char *ExtractFromContentType(char *ContentType,char *value) char *lowered = _strdup(ContentType); ToLower(lowered); char *finder=strstr(lowered,value); - if (finder==NULL){ + if (finder==NULL) { free (lowered); return NULL; } @@ -531,7 +531,7 @@ void ParseAPart(APartDataType *data) while(ENDLINEWS(finder)) finder++; //at the start of line - if (finder>data->Src){ + if (finder>data->Src) { if (*(finder-2)=='\r' || *(finder-2)=='\n') *(finder-2)=0; if (*(finder-1)=='\r' || *(finder-1)=='\n') @@ -572,7 +572,7 @@ void ParseAPart(APartDataType *data) finder++; if (ENDLINE(finder)) { // end of headers. message body begins - if (finder>data->Src){ + if (finder>data->Src) { if (*(finder-2)=='\r' || *(finder-2)=='\n') *(finder-2)=0; if (*(finder-1)=='\r' || *(finder-1)=='\n') @@ -584,7 +584,7 @@ void ParseAPart(APartDataType *data) while (!EOS(finder+1))finder++; if (ENDLINE(finder))finder--; prev2 = finder; - if (prev2>prev1){ // yes, we have body + if (prev2>prev1) { // yes, we have body data->body = prev1; } break; // there is nothing else @@ -616,7 +616,7 @@ WCHAR *ParseMultipartBody(char *src, char *bond) APartDataType *partData = new APartDataType[numparts]; memset(partData, 0, sizeof(APartDataType)*numparts); partData[0].Src = courbond = srcback; - for (i=1;(courbond=strstr(courbond,bond));i++,courbond+=sizebond){ + for (i=1;(courbond=strstr(courbond,bond));i++,courbond+=sizebond) { *(courbond-2) = 0; partData[i].Src = courbond+sizebond; while (ENDLINE(partData[i].Src)) partData[i].Src++; @@ -624,12 +624,12 @@ WCHAR *ParseMultipartBody(char *src, char *bond) size_t resultSize=0; for (i=0;iSend("STLS\r\n"); free(temp); temp=RecvRest(NetClient->Recv(),POP3_SEARCHACK); - if (AckFlag==POP3_FOK){ // Ok, we are going to tls + if (AckFlag==POP3_FOK) { // Ok, we are going to tls try { NetClient->SSLify(); } catch (...) { diff --git a/plugins/YAMN/src/proto/pop3/pop3comm.cpp b/plugins/YAMN/src/proto/pop3/pop3comm.cpp index 98888a1733..2139a93375 100644 --- a/plugins/YAMN/src/proto/pop3/pop3comm.cpp +++ b/plugins/YAMN/src/proto/pop3/pop3comm.cpp @@ -410,7 +410,7 @@ HYAMNMAIL WINAPI CreatePOP3Mail(HACCOUNT Account,DWORD MailDataVersion) return (HYAMNMAIL)NewMail; } -static void SetContactStatus(HACCOUNT account, int status){ +static void SetContactStatus(HACCOUNT account, int status) { if ((account->hContact) && (account->NewMailN.Flags & YAMN_ACC_CONT)) { DBWriteContactSettingWord(account->hContact, YAMN_DBMODULE, "Status", status); } @@ -708,10 +708,10 @@ DWORD WINAPI SynchroPOP3(struct CheckParam * WhichTemp) DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write enter\n"); #endif ActualAccount->LastChecked=now; - for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next){ - if (MsgQueuePtr->Flags&YAMN_MSG_BODYREQUESTED){ + for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next) { + if (MsgQueuePtr->Flags&YAMN_MSG_BODYREQUESTED) { HYAMNMAIL NewMsgsPtr=NULL; - for (NewMsgsPtr=(HYAMNMAIL)NewMails;NewMsgsPtr!=NULL;NewMsgsPtr=NewMsgsPtr->Next){ + for (NewMsgsPtr=(HYAMNMAIL)NewMails;NewMsgsPtr!=NULL;NewMsgsPtr=NewMsgsPtr->Next) { if (!strcmp(MsgQueuePtr->ID,NewMsgsPtr->ID)) { TCHAR accstatus[512]; wsprintf(accstatus,TranslateT("Reading body %s"),NewMsgsPtr->ID); @@ -769,12 +769,11 @@ DWORD WINAPI SynchroPOP3(struct CheckParam * WhichTemp) DebugLog(SynchroFile,"CheckPOP3:ActualAccountMsgsSO-write done\n"); #endif MsgsWriteDone(ActualAccount); - for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next){ + for (MsgQueuePtr=(HYAMNMAIL)ActualAccount->Mails;MsgQueuePtr!=NULL;MsgQueuePtr=MsgQueuePtr->Next) { if ((MsgQueuePtr->Flags&YAMN_MSG_BODYREQUESTED) && (MsgQueuePtr->Flags&YAMN_MSG_BODYRECEIVED)) { MsgQueuePtr->Flags&=~YAMN_MSG_BODYREQUESTED; - if (MsgQueuePtr->MsgWindow){ + if (MsgQueuePtr->MsgWindow) SendMessage(MsgQueuePtr->MsgWindow,WM_YAMN_CHANGECONTENT,0,0); - } } } diff --git a/plugins/YAMN/src/services.cpp b/plugins/YAMN/src/services.cpp index 7254a02428..e4a6faedf9 100644 --- a/plugins/YAMN/src/services.cpp +++ b/plugins/YAMN/src/services.cpp @@ -32,7 +32,7 @@ static INT_PTR Service_GetStatus(WPARAM wParam, LPARAM lParam) static INT_PTR Service_SetStatus(WPARAM wParam, LPARAM lParam) { int newstatus = (wParam != ID_STATUS_OFFLINE)?ID_STATUS_ONLINE:ID_STATUS_OFFLINE; - if (newstatus != YAMN_STATUS){ + if (newstatus != YAMN_STATUS) { int oldstatus = YAMN_STATUS; YAMN_STATUS = newstatus; ProtoBroadcastAck(YAMN_DBMODULE, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldstatus, newstatus); @@ -124,7 +124,8 @@ static INT_PTR ContactApplication(WPARAM wParam, LPARAM lParam) } DWORD WINAPI SWMRGWaitToRead(PSWMRG pSWMRG, DWORD dwTimeout); -static INT_PTR AccountMailCheck(WPARAM wParam, LPARAM lParam){ +static INT_PTR AccountMailCheck(WPARAM wParam, LPARAM lParam) +{ //This service will check/sincronize the account pointed by wParam HACCOUNT ActualAccount = (HACCOUNT)wParam; HANDLE ThreadRunningEV; @@ -367,10 +368,11 @@ void HookEvents(void) hookData[i].hookHandle = HookEvent(hookData[i].hookName, hookData[i].mirandaFunction); } } -void UnhookEvents(void){ - for (int i = 0;i<(sizeof(hookData)/sizeof(hookData[0]));i++) { - if (hookData[i].hookHandle) UnhookEvent(hookData[i].hookHandle); - } +void UnhookEvents(void) +{ + for (int i = 0;i<(sizeof(hookData)/sizeof(hookData[0]));i++) + if (hookData[i].hookHandle) + UnhookEvent(hookData[i].hookHandle); } typedef struct { HANDLE serviceHandle; const char *serviceName; MIRANDASERVICE serviceFunction;} ServiceDataType; diff --git a/plugins/YAMN/src/yamn.cpp b/plugins/YAMN/src/yamn.cpp index c93225e609..3bc9d3929b 100644 --- a/plugins/YAMN/src/yamn.cpp +++ b/plugins/YAMN/src/yamn.cpp @@ -205,7 +205,7 @@ void CALLBACK TimerProc(HWND, UINT, UINT, DWORD) { goto ChangeIsCountingStatusLabel; } - if (ActualAccount->TimeLeft){ + if (ActualAccount->TimeLeft) { ActualAccount->TimeLeft--; isAccountCounting = TRUE; } @@ -239,10 +239,10 @@ ChangeIsCountingStatusLabel: #ifdef DEBUG_SYNCHRO DebugLog(SynchroFile, "TimerProc:ActualAccountSO-read done\n"); #endif - if (((ActualAccount->isCounting)!=0)!=isAccountCounting){ + if (((ActualAccount->isCounting)!=0)!=isAccountCounting) { ActualAccount->isCounting=isAccountCounting; WORD cStatus = DBGetContactSettingWord(ActualAccount->hContact, YAMN_DBMODULE, "Status", 0); - switch (cStatus){ + switch (cStatus) { case ID_STATUS_ONLINE: case ID_STATUS_OFFLINE: DBWriteContactSettingWord(ActualAccount->hContact, YAMN_DBMODULE, "Status", isAccountCounting?ID_STATUS_ONLINE:ID_STATUS_OFFLINE); -- cgit v1.2.3