git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@568 77e5149b-7576-45b1-b177-96237e5ba77b
Nigel Horne authored on 2004/05/19 19:04:21... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Wed May 19 11:02:53 BST 2004 (njh) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav/message.c: Assume attachments which don't declare how |
|
4 |
+ they've been encoded are base64 |
|
5 |
+ |
|
1 | 6 |
Wed May 19 09:10:12 BST 2004 (trog) |
2 | 7 |
----------------------------------- |
3 | 8 |
* libclamav/ole2_extract.c: use mmap() when available. |
... | ... |
@@ -17,6 +17,9 @@ |
17 | 17 |
* |
18 | 18 |
* Change History: |
19 | 19 |
* $Log: message.c,v $ |
20 |
+ * Revision 1.56 2004/05/19 10:02:25 nigelhorne |
|
21 |
+ * Default encoding for attachments set to base64 |
|
22 |
+ * |
|
20 | 23 |
* Revision 1.55 2004/05/10 11:24:18 nigelhorne |
21 | 24 |
* Handle bounce message false positives |
22 | 25 |
* |
... | ... |
@@ -162,7 +165,7 @@ |
162 | 162 |
* uuencodebegin() no longer static |
163 | 163 |
* |
164 | 164 |
*/ |
165 |
-static char const rcsid[] = "$Id: message.c,v 1.55 2004/05/10 11:24:18 nigelhorne Exp $"; |
|
165 |
+static char const rcsid[] = "$Id: message.c,v 1.56 2004/05/19 10:02:25 nigelhorne Exp $"; |
|
166 | 166 |
|
167 | 167 |
#if HAVE_CONFIG_H |
168 | 168 |
#include "clamav-config.h" |
... | ... |
@@ -251,8 +254,10 @@ messageCreate(void) |
251 | 251 |
{ |
252 | 252 |
message *m = (message *)cli_calloc(1, sizeof(message)); |
253 | 253 |
|
254 |
- m->mimeType = NOMIME; |
|
255 |
- m->encodingType = NOENCODING; |
|
254 |
+ if(m) { |
|
255 |
+ m->mimeType = NOMIME; |
|
256 |
+ m->encodingType = NOENCODING; |
|
257 |
+ } |
|
256 | 258 |
|
257 | 259 |
return m; |
258 | 260 |
} |
... | ... |
@@ -443,8 +448,15 @@ messageAddArgument(message *m, const char *arg) |
443 | 443 |
return; /* already in there */ |
444 | 444 |
|
445 | 445 |
if(offset == m->numberOfArguments) { |
446 |
+ char **ptr; |
|
447 |
+ |
|
446 | 448 |
m->numberOfArguments++; |
447 |
- m->mimeArguments = (char **)cli_realloc(m->mimeArguments, m->numberOfArguments * sizeof(char *)); |
|
449 |
+ ptr = (char **)cli_realloc(m->mimeArguments, m->numberOfArguments * sizeof(char *)); |
|
450 |
+ if(ptr == NULL) { |
|
451 |
+ m->numberOfArguments--; |
|
452 |
+ return; |
|
453 |
+ } |
|
454 |
+ m->mimeArguments = ptr; |
|
448 | 455 |
} |
449 | 456 |
|
450 | 457 |
m->mimeArguments[offset] = strdup(arg); |
... | ... |
@@ -550,7 +562,7 @@ messageAddArguments(message *m, const char *s) |
550 | 550 |
|
551 | 551 |
data = strdup(cptr); |
552 | 552 |
|
553 |
- ptr = strchr(data, '"'); |
|
553 |
+ ptr = (data) ? strchr(data, '"') : NULL; |
|
554 | 554 |
if(ptr == NULL) { |
555 | 555 |
/* |
556 | 556 |
* Weird e-mail header such as: |
... | ... |
@@ -564,7 +576,8 @@ messageAddArguments(message *m, const char *s) |
564 | 564 |
* virus checked |
565 | 565 |
*/ |
566 | 566 |
cli_warnmsg("Can't parse header \"%s\"\n", s); |
567 |
- free(data); |
|
567 |
+ if(data) |
|
568 |
+ free(data); |
|
568 | 569 |
free((char *)key); |
569 | 570 |
return; |
570 | 571 |
} |
... | ... |
@@ -572,7 +585,8 @@ messageAddArguments(message *m, const char *s) |
572 | 572 |
*ptr = '\0'; |
573 | 573 |
|
574 | 574 |
field = cli_malloc(strlen(key) + strlen(data) + 2); |
575 |
- sprintf(field, "%s=%s", key, data); |
|
575 |
+ if(field) |
|
576 |
+ sprintf(field, "%s=%s", key, data); |
|
576 | 577 |
|
577 | 578 |
free((char *)key); |
578 | 579 |
free(data); |
... | ... |
@@ -594,11 +608,15 @@ messageAddArguments(message *m, const char *s) |
594 | 594 |
len = (size_t)string - (size_t)key + 1; |
595 | 595 |
field = cli_malloc(len); |
596 | 596 |
|
597 |
- memcpy(field, key, len - 1); |
|
598 |
- field[len - 1] = '\0'; |
|
597 |
+ if(field) { |
|
598 |
+ memcpy(field, key, len - 1); |
|
599 |
+ field[len - 1] = '\0'; |
|
600 |
+ } |
|
601 |
+ } |
|
602 |
+ if(field) { |
|
603 |
+ messageAddArgument(m, field); |
|
604 |
+ free(field); |
|
599 | 605 |
} |
600 |
- messageAddArgument(m, field); |
|
601 |
- free(field); |
|
602 | 606 |
} |
603 | 607 |
} |
604 | 608 |
|
... | ... |
@@ -649,6 +667,9 @@ messageFindArgument(const message *m, const char *variable) |
649 | 649 |
char *ret = strdup(++ptr); |
650 | 650 |
char *p; |
651 | 651 |
|
652 |
+ if(ret == NULL) |
|
653 |
+ return NULL; |
|
654 |
+ |
|
652 | 655 |
ret[strlen(ret) - 1] = '\0'; |
653 | 656 |
/* |
654 | 657 |
* Thomas Lamy <Thomas.Lamy@in-online.net>: |
... | ... |
@@ -662,12 +683,12 @@ messageFindArgument(const message *m, const char *variable) |
662 | 662 |
*/ |
663 | 663 |
if((p = strchr(ret, '"')) != NULL) |
664 | 664 |
*p = '\0'; |
665 |
- return(ret); |
|
665 |
+ return ret; |
|
666 | 666 |
} |
667 |
- return(strdup(ptr)); |
|
667 |
+ return strdup(ptr); |
|
668 | 668 |
} |
669 | 669 |
} |
670 |
- return(NULL); |
|
670 |
+ return NULL; |
|
671 | 671 |
} |
672 | 672 |
|
673 | 673 |
void |
... | ... |
@@ -785,7 +806,7 @@ messageAddLineAtTop(message *m, const char *line) |
785 | 785 |
|
786 | 786 |
if(m->body_first == NULL) |
787 | 787 |
return messageAddLine(m, line, 1); |
788 |
- |
|
788 |
+ |
|
789 | 789 |
oldfirst = m->body_first; |
790 | 790 |
m->body_first = (text *)cli_malloc(sizeof(text)); |
791 | 791 |
if(m->body_first == NULL) { |
... | ... |
@@ -873,7 +894,8 @@ messageToBlob(message *m) |
873 | 873 |
unsigned char byte; |
874 | 874 |
unsigned long len, l, newlen = 0L; |
875 | 875 |
char *filename; |
876 |
- unsigned char *ptr, *data; |
|
876 |
+ unsigned char *uptr, *data; |
|
877 |
+ char *ptr; |
|
877 | 878 |
int bytenumber; |
878 | 879 |
blob *tmp = blobCreate(); |
879 | 880 |
|
... | ... |
@@ -933,16 +955,21 @@ messageToBlob(message *m) |
933 | 933 |
*/ |
934 | 934 |
cli_dbgmsg("decode HQX7 message (%lu bytes)\n", len); |
935 | 935 |
|
936 |
- ptr = cli_malloc(len); |
|
937 |
- memcpy(ptr, data, len); |
|
936 |
+ uptr = cli_malloc(len); |
|
937 |
+ if(uptr == NULL) { |
|
938 |
+ blobDestroy(tmp); |
|
939 |
+ blobDestroy(b); |
|
940 |
+ return NULL; |
|
941 |
+ } |
|
942 |
+ memcpy(uptr, data, len); |
|
938 | 943 |
bytenumber = 0; |
939 | 944 |
|
940 | 945 |
/* |
941 |
- * ptr now contains the encoded (7bit) data - len bytes long |
|
946 |
+ * uptr now contains the encoded (7bit) data - len bytes long |
|
942 | 947 |
* data will contain the unencoded (8bit) data |
943 | 948 |
*/ |
944 | 949 |
for(l = 1; l < len; l++) { |
945 |
- unsigned char c = ptr[l]; |
|
950 |
+ unsigned char c = uptr[l]; |
|
946 | 951 |
|
947 | 952 |
if(c == ':') |
948 | 953 |
break; |
... | ... |
@@ -991,7 +1018,7 @@ messageToBlob(message *m) |
991 | 991 |
* |
992 | 992 |
* The data array may contain repetitive characters |
993 | 993 |
*/ |
994 |
- free(ptr); |
|
994 |
+ free(uptr); |
|
995 | 995 |
|
996 | 996 |
/* |
997 | 997 |
* Uncompress repetitive characters |
... | ... |
@@ -1053,13 +1080,20 @@ messageToBlob(message *m) |
1053 | 1053 |
*/ |
1054 | 1054 |
byte = data[0]; |
1055 | 1055 |
filename = cli_malloc(byte + 1); |
1056 |
+ if(filename == NULL) { |
|
1057 |
+ blobDestroy(b); |
|
1058 |
+ blobDestroy(tmp); |
|
1059 |
+ return NULL; |
|
1060 |
+ } |
|
1056 | 1061 |
memcpy(filename, &data[1], byte); |
1057 | 1062 |
filename[byte] = '\0'; |
1058 | 1063 |
blobSetFilename(b, filename); |
1059 | 1064 |
ptr = cli_malloc(strlen(filename) + 6); |
1060 |
- sprintf(ptr, "name=%s", filename); |
|
1061 |
- messageAddArgument(m, ptr); |
|
1062 |
- free(ptr); |
|
1065 |
+ if(ptr) { |
|
1066 |
+ sprintf(ptr, "name=%s", filename); |
|
1067 |
+ messageAddArgument(m, ptr); |
|
1068 |
+ free(ptr); |
|
1069 |
+ } |
|
1063 | 1070 |
|
1064 | 1071 |
/* |
1065 | 1072 |
* skip over length, filename, version, type, creator and flags |
... | ... |
@@ -1101,7 +1135,12 @@ messageToBlob(message *m) |
1101 | 1101 |
cli_dbgmsg("Attachment sent with no filename\n"); |
1102 | 1102 |
messageAddArgument(m, "name=attachment"); |
1103 | 1103 |
filename = strdup("attachment"); |
1104 |
- } |
|
1104 |
+ } else if(messageGetEncoding(m) == NOENCODING) |
|
1105 |
+ /* |
|
1106 |
+ * Some virus attachments don't say how they've |
|
1107 |
+ * been encoded. We assume base64 |
|
1108 |
+ */ |
|
1109 |
+ messageSetEncoding(m, "base64"); |
|
1105 | 1110 |
} |
1106 | 1111 |
|
1107 | 1112 |
blobSetFilename(b, filename); |
... | ... |
@@ -1184,6 +1223,8 @@ messageToText(const message *m) |
1184 | 1184 |
|
1185 | 1185 |
if((last == NULL) || |
1186 | 1186 |
((last->t_text = strdup(t_line->t_text)) == NULL)) { |
1187 |
+ if(last) |
|
1188 |
+ free(last); |
|
1187 | 1189 |
textDestroy(first); |
1188 | 1190 |
return NULL; |
1189 | 1191 |
} |
... | ... |
@@ -1226,8 +1267,11 @@ messageToText(const message *m) |
1226 | 1226 |
last = last->t_next; |
1227 | 1227 |
} |
1228 | 1228 |
|
1229 |
- last->t_text = strdup((char *)data); |
|
1230 |
- assert(last->t_text != NULL); |
|
1229 |
+ if(last) |
|
1230 |
+ last->t_text = strdup((char *)data); |
|
1231 |
+ |
|
1232 |
+ if((last == NULL) || (last->t_text == NULL)) |
|
1233 |
+ break; |
|
1231 | 1234 |
|
1232 | 1235 |
if(messageGetEncoding(m) == BASE64) |
1233 | 1236 |
if(strchr(line, '=')) |
... | ... |
@@ -1427,6 +1471,9 @@ decodeLine(const message *m, const char *line, unsigned char *buf, size_t buflen |
1427 | 1427 |
* but many e-mail clients ignore that |
1428 | 1428 |
*/ |
1429 | 1429 |
copy = strdup(line); |
1430 |
+ if(copy == NULL) |
|
1431 |
+ break; |
|
1432 |
+ |
|
1430 | 1433 |
p2 = strchr(copy, '='); |
1431 | 1434 |
if(p2) |
1432 | 1435 |
*p2 = '\0'; |