Browse code

Handle quotes around mime type

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

Nigel Horne authored on 2004/09/16 23:26:20
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Thu Sep 16 15:25:26 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	Handle mime types in quotation marks such as:
4
+				Content-Type: "multipart/mixed"
5
+
1 6
 Thu Sep 16 14:30:15 BST 2004 (trog)
2 7
 -----------------------------------
3 8
   * libclamav/htmlnorm.c: properly initialise output buffer
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.126  2004/09/16 14:23:57  nigelhorne
21
+ * Handle quotes around mime type
22
+ *
20 23
  * Revision 1.125  2004/09/16 12:59:36  nigelhorne
21 24
  * Handle = and space as header separaters
22 25
  *
... ...
@@ -363,7 +366,7 @@
363 363
  * Compilable under SCO; removed duplicate code with message.c
364 364
  *
365 365
  */
366
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.125 2004/09/16 12:59:36 nigelhorne Exp $";
366
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.126 2004/09/16 14:23:57 nigelhorne Exp $";
367 367
 
368 368
 #if HAVE_CONFIG_H
369 369
 #include "clamav-config.h"
... ...
@@ -862,7 +865,7 @@ parseEmailHeaders(const message *m, const table_t *rfc821)
862 862
 static int
863 863
 parseEmailHeader(message *m, const char *line, const table_t *rfc821)
864 864
 {
865
-	char *cmd, *ptr;
865
+	char *cmd;
866 866
 	int ret = -1;
867 867
 #ifdef CL_THREAD_SAFE
868 868
 	char *strptr;
... ...
@@ -2171,18 +2174,40 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2171 2171
 					strtok_r(copy, ";", &strptr);
2172 2172
 				} else {
2173 2173
 					char *s;
2174
-
2175
-					messageSetMimeType(m, strtok_r(copy, "/", &strptr));
2174
+					size_t len;
2176 2175
 
2177 2176
 					/*
2178
-					 * Stephen White <stephen@earth.li>
2179
-					 * Some clients put space after
2180
-					 * the mime type but before
2181
-					 * the ;
2177
+					 * The content type could be in quotes:
2178
+					 *	Content-Type: "multipart/mixed"
2179
+					 * FIXME: this is a hack in that ignores
2180
+					 *	the quotes, it doesn't handle
2181
+					 *	them properly
2182 2182
 					 */
2183
-					s = strtok_r(NULL, ";", &strptr);
2184
-					strstrip(s);
2185
-					messageSetMimeSubtype(m, s);
2183
+					while(isspace(*copy))
2184
+						copy++;
2185
+					if(copy[0] == '\"')
2186
+						copy++;
2187
+					if(copy[0] != '/') {
2188
+						messageSetMimeType(m, strtok_r(copy, "/", &strptr));
2189
+
2190
+						/*
2191
+						 * Stephen White <stephen@earth.li>
2192
+						 * Some clients put space after
2193
+						 * the mime type but before
2194
+						 * the ;
2195
+						 */
2196
+						s = strtok_r(NULL, ";", &strptr);
2197
+						if(s) {
2198
+							len = strstrip(s) - 1;
2199
+							if(s[len] == '\"') {
2200
+								s[len] = '\0';
2201
+								len = strstrip(s);
2202
+							}
2203
+							if(len)
2204
+								messageSetMimeSubtype(m, s);
2205
+						}
2206
+					} else
2207
+						(void)strtok_r(copy, ";", &strptr);
2186 2208
 				}
2187 2209
 
2188 2210
 				/*
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.82  2004/09/16 14:23:57  nigelhorne
21
+ * Handle quotes around mime type
22
+ *
20 23
  * Revision 1.81  2004/09/16 12:59:36  nigelhorne
21 24
  * Handle = and space as header separaters
22 25
  *
... ...
@@ -240,7 +243,7 @@
240 240
  * uuencodebegin() no longer static
241 241
  *
242 242
  */
243
-static	char	const	rcsid[] = "$Id: message.c,v 1.81 2004/09/16 12:59:36 nigelhorne Exp $";
243
+static	char	const	rcsid[] = "$Id: message.c,v 1.82 2004/09/16 14:23:57 nigelhorne Exp $";
244 244
 
245 245
 #if HAVE_CONFIG_H
246 246
 #include "clamav-config.h"
... ...
@@ -387,6 +390,9 @@ messageReset(message *m)
387 387
 	m->mimeType = NOMIME;
388 388
 }
389 389
 
390
+/*
391
+ * Handle the Content-Type header
392
+ */
390 393
 void
391 394
 messageSetMimeType(message *mess, const char *type)
392 395
 {