Browse code

Handle RFC822 Comments

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

Nigel Horne authored on 2004/09/16 17:58:56
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Sep 16 09:58:01 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	Handle comments in the headers
4
+
1 5
 Wed Sep 15 23:09:39 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * libclamav/mbox.c:	FOLLOWURLS: check if normalisation is successful
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.123  2004/09/16 08:56:19  nigelhorne
21
+ * Handle RFC822 Comments
22
+ *
20 23
  * Revision 1.122  2004/09/15 22:09:26  nigelhorne
21 24
  * Handle spaces before colons
22 25
  *
... ...
@@ -354,7 +357,7 @@
354 354
  * Compilable under SCO; removed duplicate code with message.c
355 355
  *
356 356
  */
357
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.122 2004/09/15 22:09:26 nigelhorne Exp $";
357
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.123 2004/09/16 08:56:19 nigelhorne Exp $";
358 358
 
359 359
 #if HAVE_CONFIG_H
360 360
 #include "clamav-config.h"
... ...
@@ -2014,16 +2017,75 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2014 2014
 #ifdef CL_THREAD_SAFE
2015 2015
 	char *strptr;
2016 2016
 #endif
2017
-	char *copy = strdup(arg ? arg : "");
2018
-	char *ptr = copy;
2019
-
2020
-	if(copy == NULL)
2021
-		return -1;
2017
+	char *copy, *ptr;
2018
+	int commandNumber;
2022 2019
 
2023 2020
 	cli_dbgmsg("parseMimeHeader: cmd='%s', arg='%s'\n", cmd, arg);
2021
+
2022
+	if(strchr(cmd, '(')) {
2023
+		/*
2024
+		 * The command includes comments, see section 3.4.3 of RFC822
2025
+		 * Remove the comment from the command
2026
+		 */
2027
+		char *ccopy = strdup(cmd);
2028
+		char *cptr;
2029
+		int backslash, inquote, commentlevel;
2030
+		char *newcmd, *nptr;
2031
+
2032
+		if(ccopy == NULL)
2033
+			return -1;
2034
+
2035
+		newcmd = cli_malloc(strlen(cmd) + 1);
2036
+		if(newcmd == NULL) {
2037
+			free(ccopy);
2038
+			return -1;
2039
+		}
2040
+
2041
+		backslash = commentlevel = inquote = 0;
2042
+		nptr = newcmd;
2043
+
2044
+		cli_dbgmsg("parseMimeHeader: cmd contains a comment\n");
2045
+
2046
+		for(cptr = ccopy; *cptr; cptr++)
2047
+			if(backslash) {
2048
+				*nptr++ = *cptr;
2049
+				backslash = 0;
2050
+			} else switch(*cptr) {
2051
+				case '\\':
2052
+					backslash = 1;
2053
+					break;
2054
+				case '\"':
2055
+					inquote = !inquote;
2056
+					break;
2057
+				case '(':
2058
+					commentlevel++;
2059
+					break;
2060
+				case ')':
2061
+					if(commentlevel > 0)
2062
+						commentlevel--;
2063
+					break;
2064
+				default:
2065
+					if(commentlevel == 0)
2066
+						*nptr++ = *cptr;
2067
+			}
2068
+
2069
+		if(backslash)	/* last character was a single backslash */
2070
+			*nptr++ = '\\';
2071
+		*nptr = '\0';
2072
+
2073
+		free(ccopy);
2074
+		commandNumber = tableFind(rfc821Table, newcmd);
2075
+		free(newcmd);
2076
+	} else
2077
+		commandNumber = tableFind(rfc821Table, cmd);
2078
+
2079
+	copy = strdup(arg ? arg : "");
2024 2080
 	strstrip(copy);
2081
+	ptr = copy;
2082
+	if(copy == NULL)
2083
+		return -1;
2025 2084
 
2026
-	switch(tableFind(rfc821Table, cmd)) {
2085
+	switch(commandNumber) {
2027 2086
 		case CONTENT_TYPE:
2028 2087
 			/*
2029 2088
 			 * Fix for non RFC1521 compliant mailers