Browse code

Use stack rather than heap where possible

git-svn: trunk@947

Nigel Horne authored on 2004/09/29 03:40:12
Showing 1 changed files
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.142  2004/09/28 18:40:12  nigelhorne
21
+ * Use stack rather than heap where possible
22
+ *
20 23
  * Revision 1.141  2004/09/23 08:43:25  nigelhorne
21 24
  * Scan multipart/digest messages
22 25
  *
... ...
@@ -411,7 +414,7 @@
411 411
  * Compilable under SCO; removed duplicate code with message.c
412 412
  *
413 413
  */
414
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.141 2004/09/23 08:43:25 nigelhorne Exp $";
414
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.142 2004/09/28 18:40:12 nigelhorne Exp $";
415 415
 
416 416
 #if HAVE_CONFIG_H
417 417
 #include "clamav-config.h"
... ...
@@ -877,7 +880,10 @@ parseEmailHeaders(const message *m, const table_t *rfc821)
877 877
 				 * Add all the arguments on the line
878 878
 				 */
879 879
 				const char *ptr;
880
-				char *copy = strdup(buffer);
880
+				char copy[LINE_LENGTH + 1];
881
+
882
+				assert(strlen(buffer) < sizeof(copy));
883
+				strcpy(copy, buffer);
881 884
 
882 885
 #ifdef	CL_THREAD_SAFE
883 886
 				for(ptr = strtok_r(copy, ";", &strptr); ptr; ptr = strtok_r(NULL, ":", &strptr))
... ...
@@ -888,7 +894,6 @@ parseEmailHeaders(const message *m, const table_t *rfc821)
888 888
 					if(strchr(ptr, '='))
889 889
 						messageAddArguments(ret, ptr);
890 890
 #endif
891
-				free(copy);
892 891
 			} else {
893 892
 				Xheader = (bool)(buffer[0] == 'X');
894 893
 				messageAddArgument(ret, buffer);
... ...
@@ -1056,12 +1061,9 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1056 1056
 				 * able to scan anyway and we lose nothing
1057 1057
 				 */
1058 1058
 				aText = textCopy(messageGetBody(mainMessage));
1059
-			/*
1060
-			 * TODO
1061
-			else if(options&CL_MAILURL)
1059
+			else if(options&CL_SCAN_MAILURL)
1062 1060
 				if(tableFind(subtypeTable, mimeSubtype) == HTML)
1063 1061
 					checkURLs(mainMessage, dir);
1064
-			 */
1065 1062
 			break;
1066 1063
 		case MULTIPART:
1067 1064
 			boundary = messageFindArgument(mainMessage, "boundary");
... ...
@@ -1252,6 +1254,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1252 1252
 							const text *next = t_line->t_next;
1253 1253
 							char *fullline = strdup(line);
1254 1254
 
1255
+							assert(strlen(line) <= LINE_LENGTH);
1255 1256
 							/*
1256 1257
 							 * Fold next lines to the end of this
1257 1258
 							 * if they start with a white space
... ...
@@ -2355,7 +2358,7 @@ saveTextPart(message *m, const char *dir)
2355 2355
 		/*
2356 2356
 		 * Save main part to scan that
2357 2357
 		 */
2358
-		cli_dbgmsg("Saving main message, encoded with scheme\n");
2358
+		cli_dbgmsg("Saving main message\n");
2359 2359
 
2360 2360
 		fileblobDestroy(fb);
2361 2361
 	}
... ...
@@ -2447,9 +2450,10 @@ rfc2047(const char *in)
2447 2447
 
2448 2448
 	/* For each RFC2047 string */
2449 2449
 	while(*in) {
2450
-		char encoding, *enctext, *ptr;
2450
+		char encoding, *ptr;
2451 2451
 		message *m;
2452 2452
 		blob *b;
2453
+		char enctext[LINE_LENGTH + 1];
2453 2454
 
2454 2455
 		/* Find next RFC2047 string */
2455 2456
 		while(*in) {
... ...
@@ -2477,12 +2481,11 @@ rfc2047(const char *in)
2477 2477
 		if(*++in == '\0')
2478 2478
 			break;
2479 2479
 
2480
-		enctext = strdup(in);
2480
+		assert(strlen(in) < sizeof(enctext));
2481
+		strcpy(enctext, in);
2481 2482
 		in = strstr(in, "?=");
2482
-		if(in == NULL) {
2483
-			free(enctext);
2483
+		if(in == NULL)
2484 2484
 			break;
2485
-		}
2486 2485
 		in += 2;
2487 2486
 		ptr = strstr(enctext, "?=");
2488 2487
 		assert(ptr != NULL);
... ...
@@ -2490,12 +2493,9 @@ rfc2047(const char *in)
2490 2490
 		/*cli_dbgmsg("Need to decode '%s' with method '%c'\n", enctext, encoding);*/
2491 2491
 
2492 2492
 		m = messageCreate();
2493
-		if(m == NULL) {
2494
-			free(enctext);
2493
+		if(m == NULL)
2495 2494
 			break;
2496
-		}
2497 2495
 		messageAddStr(m, enctext);
2498
-		free(enctext);
2499 2496
 		switch(encoding) {
2500 2497
 			case 'q':
2501 2498
 				messageSetEncoding(m, "quoted-printable");