summaryrefslogtreecommitdiff
path: root/plugins/YAMN/src/mails
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-01-03 22:11:27 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-01-03 22:11:27 +0000
commit53e568efe6f2a9e121ac6cf305e5fa9a84137c1a (patch)
tree60185775025f8fe3a7ed8f1f78b041c5db5770c1 /plugins/YAMN/src/mails
parentb06a96420250b0a6b8de0a3c463e4599ba16e522 (diff)
- 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
Diffstat (limited to 'plugins/YAMN/src/mails')
-rw-r--r--plugins/YAMN/src/mails/decode.cpp8
-rw-r--r--plugins/YAMN/src/mails/mails.cpp4
-rw-r--r--plugins/YAMN/src/mails/mime.cpp55
3 files changed, 34 insertions, 33 deletions
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++<DstLen);Src++,Dst++)
if (*Src=='=')
{
- if (!isQ){
- if (Src[1]==0x0D){
+ if (!isQ) {
+ if (Src[1]==0x0D) {
Src++; Src++;
if (Src[0]==0x0A) Src++;
goto CopyCharQuotedPrintable;
}
- if (Src[1]==0x0A){
+ if (Src[1]==0x0A) {
Src++; Src++;
goto CopyCharQuotedPrintable;
}
@@ -455,7 +455,7 @@ void ConvertCodedStringToUnicode(char *stream,WCHAR **storeto,DWORD cp,int mode)
size_t tempstoreLength = wcslen(tempstore);
size_t outind = 0;
- while(*start!=0){
+ while(*start!=0) {
if (CODES(start)) {
finder=start+2;finderend=finder;
while(!CODED(finderend) && !EOS(finderend)) finderend++;
diff --git a/plugins/YAMN/src/mails/mails.cpp b/plugins/YAMN/src/mails/mails.cpp
index af0f3d2329..785fc5d8d9 100644
--- a/plugins/YAMN/src/mails/mails.cpp
+++ b/plugins/YAMN/src/mails/mails.cpp
@@ -155,7 +155,7 @@ INT_PTR DeleteAccountMailSvc(WPARAM wParam,LPARAM lParam)
HYAMNMAIL OldMail=(HYAMNMAIL)lParam;
struct CMimeItem *TH;
- if (Plugin->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;i<numparts;i++) {
ParseAPart(&partData[i]);
- if (partData[i].body){
- if (partData[i].TransEnc){
+ if (partData[i].body) {
+ if (partData[i].TransEnc) {
if (!_stricmp(partData[i].TransEnc,"base64")) partData[i].TransEncType=TE_BASE64;
else if (!_stricmp(partData[i].TransEnc,"quoted-printable"))partData[i].TransEncType=TE_QUOTEDPRINTABLE;
}
- if (partData[i].ContType){
+ if (partData[i].ContType) {
char *CharSetStr;
if (NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"charset=")))
{
@@ -639,7 +639,7 @@ WCHAR *ParseMultipartBody(char *src, char *bond)
}
if (partData[i].ContType && !_strnicmp(partData[i].ContType,"text",4)) {
char *localBody=0;
- switch (partData[i].TransEncType){
+ switch (partData[i].TransEncType) {
case TE_BASE64:
{
int size =partData[i].bodyLen*3/4+5;
@@ -674,42 +674,42 @@ FailBackRaw:
dest = new WCHAR[resultSize+1];
size_t destpos = 0;
for (i=0;i<numparts;i++) {
- if (i){ // part before first boudary should not have headers
- char infoline[104]; size_t linesize = 0;
+ if (i) { // part before first boudary should not have headers
+ char infoline[1024]; size_t linesize = 0;
_snprintf(infoline,100,"%s %d",Translate("Part"),i);
linesize = strlen(infoline);
- if (partData[i].TransEnc){
- _snprintf(infoline+linesize,100-linesize,"; %s",partData[i].TransEnc);
+ if (partData[i].TransEnc) {
+ _snprintf(infoline+linesize, sizeof(infoline)-linesize,"; %s",partData[i].TransEnc);
linesize = strlen(infoline);
}
- if (partData[i].ContType){
+ if (partData[i].ContType) {
char *CharSetStr=strchr(partData[i].ContType,';');
- if (CharSetStr){
+ if (CharSetStr) {
CharSetStr[0]=0;
- _snprintf(infoline+linesize,100-linesize,"; %s",partData[i].ContType);
+ _snprintf(infoline+linesize,sizeof(infoline)-linesize,"; %s",partData[i].ContType);
linesize = strlen(infoline);
partData[i].ContType=CharSetStr+1;
- if (NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"charset=")))
- {
- _snprintf(infoline+linesize,100-linesize,"; %s",CharSetStr);
+ if (NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"charset="))) {
+ _snprintf(infoline+linesize,sizeof(infoline)-linesize,"; %s",CharSetStr);
linesize = strlen(infoline);
delete[] CharSetStr;
}
- if (NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"name=")))
- {
- _snprintf(infoline+linesize,100-linesize,"; \"%s\"",CharSetStr);
+ if (NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"name="))) {
+ _snprintf(infoline+linesize,sizeof(infoline)-linesize,"; \"%s\"",CharSetStr);
linesize = strlen(infoline);
delete[] CharSetStr;
}
- } else {
- _snprintf(infoline+linesize,100-linesize,"; %s",partData[i].ContType);
+ }
+ else {
+ _snprintf(infoline+linesize,sizeof(infoline)-linesize,"; %s",partData[i].ContType);
linesize = strlen(infoline);
}
}
sprintf(infoline+linesize,".\r\n");
- {WCHAR *temp=0;
+ {
+ WCHAR *temp=0;
dest[destpos] = dest[destpos+1] = dest[destpos+2] = 0x2022; // bullet;
- destpos+=3;
+ destpos += 3;
ConvertStringToUnicode(infoline,CP_ACP,&temp);
size_t wsize = wcslen(temp);
wcscpy(&dest[destpos],temp);
@@ -717,7 +717,8 @@ FailBackRaw:
delete[] temp;
}
} // if (i)
- if (partData[i].wBody){
+
+ if (partData[i].wBody) {
size_t wsize = wcslen(partData[i].wBody);
wcscpy(&dest[destpos],partData[i].wBody);
destpos += wsize;