Browse code

Fix crash if x-yencode is mistakenly guessed

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

Nigel Horne authored on 2004/11/08 19:30:05
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon Nov  8 10:29:02 GMT 2004 (njh)
2
+----------------------------------
3
+  * libclamav/message.c:	Fix crash if the guessed encoder is incorrectly
4
+			thought to be yEnc
5
+
1 6
 Mon Nov  8 10:28:41 CET 2004 (tk)
2 7
 ---------------------------------
3 8
   * clamd: force SHUTDOWN on memory errors from libclamav
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.168  2004/11/08 10:26:22  nigelhorne
21
+ * Fix crash if x-yencode is mistakenly guessed
22
+ *
20 23
  * Revision 1.167  2004/11/07 16:59:42  nigelhorne
21 24
  * Tidy
22 25
  *
... ...
@@ -489,7 +492,7 @@
489 489
  * Compilable under SCO; removed duplicate code with message.c
490 490
  *
491 491
  */
492
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.167 2004/11/07 16:59:42 nigelhorne Exp $";
492
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.168 2004/11/08 10:26:22 nigelhorne Exp $";
493 493
 
494 494
 #if HAVE_CONFIG_H
495 495
 #include "clamav-config.h"
... ...
@@ -784,7 +787,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
784 784
 	int retcode, i;
785 785
 	message *m, *body;
786 786
 	FILE *fd;
787
-	char buffer[LINE_LENGTH];
787
+	char buffer[LINE_LENGTH + 1];
788 788
 #ifdef HAVE_BACKTRACE
789 789
 	void (*segv)(int);
790 790
 #endif
... ...
@@ -798,7 +801,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
798 798
 		close(i);
799 799
 		return CL_EOPEN;
800 800
 	}
801
-	if(fgets(buffer, sizeof(buffer), fd) == NULL) {
801
+	if(fgets(buffer, sizeof(buffer) - 1, fd) == NULL) {
802 802
 		/* empty message */
803 803
 		fclose(fd);
804 804
 		return CL_CLEAN;
... ...
@@ -879,7 +882,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
879 879
 				lastLineWasEmpty = (bool)(buffer[0] == '\0');
880 880
 			if(messageAddStr(m, buffer) < 0)
881 881
 				break;
882
-		} while(fgets(buffer, sizeof(buffer), fd) != NULL);
882
+		} while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL);
883 883
 
884 884
 		cli_dbgmsg("Deal with email number %d\n", messagenumber);
885 885
 	} else {
... ...
@@ -892,16 +895,18 @@ cli_mbox(const char *dir, int desc, unsigned int options)
892 892
 			 * CommuniGate Pro format: ignore headers until
893 893
 			 * blank line
894 894
 			 */
895
-			while((fgets(buffer, sizeof(buffer), fd) != NULL) &&
895
+			while((fgets(buffer, sizeof(buffer) - 1, fd) != NULL) &&
896 896
 				(strchr("\r\n", buffer[0]) == NULL))
897 897
 					;
898 898
 		/*
899 899
 		 * Ignore any blank lines at the top of the message
900 900
 		 */
901 901
 		while(strchr("\r\n", buffer[0]) &&
902
-		     (fgets(buffer, sizeof(buffer), fd) != NULL))
902
+		     (fgets(buffer, sizeof(buffer) - 1, fd) != NULL))
903 903
 			;
904 904
 
905
+		buffer[LINE_LENGTH] = '\0';
906
+
905 907
 		/*
906 908
 		 * FIXME: files full of new lines and nothing else are
907 909
 		 * handled ungracefully...
... ...
@@ -917,7 +922,7 @@ cli_mbox(const char *dir, int desc, unsigned int options)
917 917
 			(void)cli_chomp(buffer);
918 918
 			if(messageAddStr(m, buffer) < 0)
919 919
 				break;
920
-		} while(fgets(buffer, sizeof(buffer), fd) != NULL);
920
+		} while(fgets(buffer, sizeof(buffer) - 1, fd) != NULL);
921 921
 	}
922 922
 
923 923
 	fclose(fd);
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.110  2004/11/08 10:26:22  nigelhorne
21
+ * Fix crash if x-yencode is mistakenly guessed
22
+ *
20 23
  * Revision 1.109  2004/11/07 16:39:00  nigelhorne
21 24
  * Handle para 4 of RFC2231
22 25
  *
... ...
@@ -324,7 +327,7 @@
324 324
  * uuencodebegin() no longer static
325 325
  *
326 326
  */
327
-static	char	const	rcsid[] = "$Id: message.c,v 1.109 2004/11/07 16:39:00 nigelhorne Exp $";
327
+static	char	const	rcsid[] = "$Id: message.c,v 1.110 2004/11/08 10:26:22 nigelhorne Exp $";
328 328
 
329 329
 #if HAVE_CONFIG_H
330 330
 #include "clamav-config.h"
... ...
@@ -699,7 +702,7 @@ messageAddArgument(message *m, const char *arg)
699 699
 		m->mimeArguments = ptr;
700 700
 	}
701 701
 
702
-	m->mimeArguments[offset] = rfc2231(arg);
702
+	arg = m->mimeArguments[offset] = rfc2231(arg);
703 703
 
704 704
 	/*
705 705
 	 * This is terribly broken from an RFC point of view but is useful
... ...
@@ -1257,6 +1260,8 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1257 1257
 	if(ret == NULL)
1258 1258
 		return NULL;
1259 1259
 
1260
+	cli_dbgmsg("messageExport: numberOfEncTypes == %d\n", m->numberOfEncTypes);
1261
+
1260 1262
 	if((t_line = binhexBegin(m)) != NULL) {
1261 1263
 		unsigned char byte;
1262 1264
 		unsigned long len, l, newlen = 0L;
... ...
@@ -1587,7 +1592,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1587 1587
 			(*setFilename)(ret, dir, filename);
1588 1588
 			t_line = t_line->t_next;
1589 1589
 			enctype = UUENCODE;
1590
-		} else if((enctype == YENCODE) || ((i == 0) && yEncBegin(m))) {
1590
+		} else if(((enctype == YENCODE) && yEncBegin(m)) || ((i == 0) && yEncBegin(m))) {
1591 1591
 			/*
1592 1592
 			 * TODO: handle multipart yEnc encoded files
1593 1593
 			 */
... ...
@@ -2544,9 +2549,8 @@ messageDedup(message *m)
2544 2544
 static char *
2545 2545
 rfc2231(const char *in)
2546 2546
 {
2547
-	char *out;
2548
-	char *ptr;
2549
-	char *ret;
2547
+	const char *ptr;
2548
+	char *ret, *out;
2550 2549
 	enum { LANGUAGE, CHARSET, CONTENTS } field = LANGUAGE;
2551 2550
 
2552 2551
 	ptr = strstr(in, "*=");
... ...
@@ -2604,11 +2608,11 @@ rfc2231(const char *in)
2604 2604
 	}
2605 2605
 
2606 2606
 	if(field != CONTENTS) {
2607
-		cli_warnmsg("Invalid RFC2231 header: '%s'\n", in);
2608 2607
 		free(ret);
2608
+		cli_warnmsg("Invalid RFC2231 header: '%s'\n", in);
2609 2609
 		return strdup("");
2610 2610
 	}
2611
-				
2611
+
2612 2612
 	*out = '\0';
2613 2613
 
2614 2614
 	cli_dbgmsg("rfc2231 returns '%s'\n", ret);