Browse code

Fix seg fault when a message in a multimessage mailbox fails to scan

git-svn: trunk@393

Nigel Horne authored on 2004/03/11 07:07:54
Showing 2 changed files
... ...
@@ -1,3 +1,9 @@
1
+Wed Mar 10 22:14:45 GMT 2004 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	Fixed segfault which happens when a UNIX mailbox
4
+  	with more than one message quits because a message before the last
5
+	one can't be parsed
6
+
1 7
 Wed Mar 10 20:51:54 CET 2004 (tk)
2 8
 ---------------------------------
3 9
   * doc: + Polish sendmail_clamav how-to updated (Przemyslaw Holowczyc
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.50  2004/03/10 22:05:39  nigelhorne
21
+ * Fix seg fault when a message in a multimessage mailbox fails to scan
22
+ *
20 23
  * Revision 1.49  2004/03/04 13:01:58  nigelhorne
21 24
  * Ensure all bounces are rescanned by cl_mbox
22 25
  *
... ...
@@ -138,7 +141,7 @@
138 138
  * Compilable under SCO; removed duplicate code with message.c
139 139
  *
140 140
  */
141
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.49 2004/03/04 13:01:58 nigelhorne Exp $";
141
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.50 2004/03/10 22:05:39 nigelhorne Exp $";
142 142
 
143 143
 #if HAVE_CONFIG_H
144 144
 #include "clamav-config.h"
... ...
@@ -346,8 +349,11 @@ cl_mbox(const char *dir, int desc)
346 346
 				messageDestroy(m);
347 347
 				messageClean(body);
348 348
 				if(messageGetBody(body))
349
-					if(!parseEmailBody(body,  NULL, 0, NULL, dir, rfc821Table, subtypeTable))
350
-						break;
349
+					if(!parseEmailBody(body,  NULL, 0, NULL, dir, rfc821Table, subtypeTable)) {
350
+						messageReset(body);
351
+						m = body;
352
+						continue;
353
+					}
351 354
 				/*
352 355
 				 * Starting a new message, throw away all the
353 356
 				 * information about the old one
... ...
@@ -355,7 +361,6 @@ cl_mbox(const char *dir, int desc)
355 355
 				m = body;
356 356
 				messageReset(body);
357 357
 
358
-				lastLineWasEmpty = TRUE;
359 358
 				cli_dbgmsg("Finished processing message\n");
360 359
 			} else
361 360
 				lastLineWasEmpty = (bool)(buffer[0] == '\0');
... ...
@@ -457,17 +462,23 @@ parseEmailHeaders(const message *m, const table_t *rfc821Table)
457 457
 			 */
458 458
 			if(strstrip(buffer) == 0) {
459 459
 				cli_dbgmsg("End of header information\n");
460
-				inHeader = FALSE;
460
+				inContinuationHeader = inHeader = FALSE;
461 461
 			} else if(parseEmailHeader(ret, buffer, rfc821Table) == CONTENT_TYPE)
462 462
 				inContinuationHeader = continuationMarker(buffer);
463 463
 
464
-		} else
464
+		} else {
465
+			/*cli_dbgmsg("Add line to body '%s'\n", buffer);*/
465 466
 			messageAddLine(ret, buffer);
467
+		}
466 468
 		free(buffer);
467 469
 	} while((t = t->t_next) != NULL);
468 470
 
471
+	cli_dbgmsg("parseEmailHeaders: calling textDestroy\n");
472
+
469 473
 	textDestroy(msgText);
470 474
 
475
+	cli_dbgmsg("parseEmailHeaders: return\n");
476
+
471 477
 	return ret;
472 478
 }
473 479
 
... ...
@@ -1607,7 +1618,7 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
1607 1607
 				 * Some clients are broken and
1608 1608
 				 * put white space after the ;
1609 1609
 				 */
1610
-				strstrip(copy);
1610
+				/*strstrip(copy);*/
1611 1611
 				if(*arg == '/') {
1612 1612
 					cli_warnmsg("Content-type '/' received, assuming application/octet-stream\n");
1613 1613
 					messageSetMimeType(m, "application");