Browse code

Improved embedded RFC822 message handling

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@410 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/03/18 04:48:33
Showing 2 changed files
... ...
@@ -1,3 +1,10 @@
1
+Wed Mar 17 19:48:56 GMT 2004 (njh)
2
+----------------------------------
3
+  * clamav-milter: upissued history to 0.70
4
+  * libclamav/message.c: Handle spaces before the disposition type
5
+  * libclamav/mbox.c:	Added some speed ups and reduced memory usage when
6
+  		scanning embedded RFC822 messages
7
+
1 8
 Wed Mar 17 15:06:44 GMT 2004 (trog)
2 9
 -----------------------------------
3 10
   * libclamav/vba_extract.c: Add VBA signature for MacOffice X
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.51  2004/03/17 19:48:12  nigelhorne
21
+ * Improved embedded RFC822 message handling
22
+ *
20 23
  * Revision 1.50  2004/03/10 22:05:39  nigelhorne
21 24
  * Fix seg fault when a message in a multimessage mailbox fails to scan
22 25
  *
... ...
@@ -141,7 +144,7 @@
141 141
  * Compilable under SCO; removed duplicate code with message.c
142 142
  *
143 143
  */
144
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.50 2004/03/10 22:05:39 nigelhorne Exp $";
144
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.51 2004/03/17 19:48:12 nigelhorne Exp $";
145 145
 
146 146
 #if HAVE_CONFIG_H
147 147
 #include "clamav-config.h"
... ...
@@ -465,7 +468,6 @@ parseEmailHeaders(const message *m, const table_t *rfc821Table)
465 465
 				inContinuationHeader = inHeader = FALSE;
466 466
 			} else if(parseEmailHeader(ret, buffer, rfc821Table) == CONTENT_TYPE)
467 467
 				inContinuationHeader = continuationMarker(buffer);
468
-
469 468
 		} else {
470 469
 			/*cli_dbgmsg("Add line to body '%s'\n", buffer);*/
471 470
 			messageAddLine(ret, buffer);
... ...
@@ -963,13 +965,24 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
963 963
 								addAttachment = TRUE;
964 964
 							}
965 965
 						} else {
966
-							cli_dbgmsg("Text type %s is not supported", dtype);
966
+							cli_warnmsg("Text type %s is not supported\n", dtype);
967 967
 							continue;
968 968
 						}
969 969
 						break;
970 970
 					case MESSAGE:
971 971
 						cli_dbgmsg("Found message inside multipart\n");
972 972
 						body = parseEmailHeaders(aMessage, rfc821Table);
973
+						/*
974
+						 * We've fininished with the
975
+						 * original copy of the message,
976
+						 * so throw that away and
977
+						 * deal with the encapsulated
978
+						 * message as a message.
979
+						 * This can save a lot of memory
980
+						 */
981
+						assert(aMessage == messages[i]);
982
+						messageDestroy(messages[i]);
983
+						messages[i] = NULL;
973 984
 						if(body) {
974 985
 							rc = parseEmailBody(body, blobs, nBlobs, NULL, dir, rfc821Table, subtypeTable);
975 986
 							messageDestroy(body);
... ...
@@ -1027,9 +1040,12 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1027 1027
 					assert(addToText || addAttachment);
1028 1028
 					assert(!(addToText && addAttachment));
1029 1029
 
1030
-					if(addToText)
1030
+					if(addToText) {
1031 1031
 						aText = textAdd(aText, messageGetBody(aMessage));
1032
-					else if(addAttachment) {
1032
+						assert(aMessage == messages[i]);
1033
+						messageDestroy(messages[i]);
1034
+						messages[i] = NULL;
1035
+					} else if(addAttachment) {
1033 1036
 						blob *aBlob = messageToBlob(aMessage);
1034 1037
 
1035 1038
 						if(aBlob) {
... ...
@@ -1088,8 +1104,8 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1088 1088
 				 * there's no more work to do.
1089 1089
 				 *
1090 1090
 				 * This is mostly for the situation where
1091
-				 * broken code which claim to be multipart
1092
-				 * which aren't was causing us to go into
1091
+				 * broken messages claim to be multipart
1092
+				 * but aren't was causing us to go into
1093 1093
 				 * infinite recursion
1094 1094
 				 */
1095 1095
 				if(multiparts > 1)
... ...
@@ -1137,7 +1153,8 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1137 1137
 			}
1138 1138
 
1139 1139
 			for(i = 0; i < multiparts; i++)
1140
-				messageDestroy(messages[i]);
1140
+				if(messages[i])
1141
+					messageDestroy(messages[i]);
1141 1142
 
1142 1143
 			if(blobs && (blobsIn == NULL))
1143 1144
 				puts("arraydestroy");
... ...
@@ -1165,6 +1182,7 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1165 1165
 			}
1166 1166
 			if((strcasecmp(mimeSubtype, "rfc822") == 0) ||
1167 1167
 			   (strcasecmp(mimeSubtype, "delivery-status") == 0)) {
1168
+#if	0
1168 1169
 				/*
1169 1170
 				 * Found a message encapsulated within
1170 1171
 				 * another message
... ...
@@ -1181,14 +1199,13 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1181 1181
 				m = messageCreate();
1182 1182
 				assert(m != NULL);
1183 1183
 
1184
-				cli_dbgmsg("Decode rfc822");
1185
-
1186 1184
 				do {
1187
-					char *buffer = strdup(t->t_text);
1185
+					/*char *buffer = strdup(t->t_text);
1188 1186
 
1189 1187
 					cli_chomp(buffer);
1190 1188
 					messageAddLine(m, buffer);
1191
-					free(buffer);
1189
+					free(buffer);*/
1190
+					messageAddLine(m, t->t_text);
1192 1191
 				} while((t = t->t_next) != NULL);
1193 1192
 
1194 1193
 				textDestroy(msgText);
... ...
@@ -1204,6 +1221,19 @@ parseEmailBody(message *messageIn, blob **blobsIn, int nBlobs, text *textIn, con
1204 1204
 					rc = parseEmailBody(m, NULL, 0, NULL, dir, rfc821Table, subtypeTable);
1205 1205
 
1206 1206
 				messageDestroy(m);
1207
+#else
1208
+				message *m = parseEmailHeaders(mainMessage, rfc821Table);
1209
+				if(m) {
1210
+					cli_dbgmsg("Decode rfc822");
1211
+
1212
+					messageClean(m);
1213
+
1214
+					if(messageGetBody(m))
1215
+						rc = parseEmailBody(m, NULL, 0, NULL, dir, rfc821Table, subtypeTable);
1216
+
1217
+					messageDestroy(m);
1218
+				}
1219
+#endif
1207 1220
 
1208 1221
 				break;
1209 1222
 			} else if(strcasecmp(mimeSubtype, "partial") == 0)