Browse code

decode_mime_type() resets the type/subtype to unknown, if the end of tree has reached, but the type/subtype has still some remaining characters

Miklos Tirpak authored on 23/05/2008 10:04:55
Showing 1 changed files
... ...
@@ -30,6 +30,9 @@
30 30
  * the mime type (bogdan)
31 31
  * 2003-08-04 CPL subtype added (bogdan)
32 32
  * 2003-08-05 parse_accept_hdr function added (bogdan)
33
+ * 2008-05-23 reset the type/subtype to unknown, if the end of
34
+ *		tree has reached, but the type/subtype has still
35
+ *		some remaining characters (Miklos)
33 36
  */
34 37
 
35 38
 
... ...
@@ -256,6 +259,7 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
256 256
 	int node;
257 257
 	char *mark;
258 258
 	char *p;
259
+	unsigned int type_candidate;
259 260
 
260 261
 	p = start;
261 262
 
... ...
@@ -273,22 +277,28 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
273 273
 	} else {
274 274
 		node = 0;
275 275
 		mark = p;
276
+		type_candidate = TYPE_UNKNOWN;
276 277
 		while (p<end && is_mime_char(*p)  ) {
277 278
 			while ( node!=-1 && !is_char_equal(*p,type_tree[node].c) ){
278 279
 				node = type_tree[node].next;
279 280
 			}
280
-			if (node!=-1 && type_tree[node].nr_sons)
281
-				node++; 
282
-				/* ? increment only for (p < end - 1), 
283
-				 * otherwise will not work for final nodes with children */
281
+			if (node!=-1) {
282
+				type_candidate = type_tree[node].final;
283
+				if (type_tree[node].nr_sons)
284
+					node++;
285
+				else
286
+					node = -1;
287
+			} else {
288
+				/* end of the type tree has reached,
289
+				but the type has still some remaining
290
+				characters (Miklos) */
291
+				type_candidate = TYPE_UNKNOWN;
292
+			}
284 293
 			p++;
285 294
 		}
286 295
 		if (p==end || mark==p)
287 296
 			goto error;
288
-		if (node!=-1)
289
-			*mime_type = type_tree[node].final<<16;
290
-		else
291
-			*mime_type = TYPE_UNKNOWN<<16;
297
+		*mime_type = type_candidate<<16;
292 298
 	}
293 299
 
294 300
 	/* search the '/' separator */
... ...
@@ -312,19 +322,27 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
312 312
 	} else {
313 313
 		node = 0;
314 314
 		mark = p;
315
+		type_candidate = SUBTYPE_UNKNOWN;
315 316
 		while (p<end && is_mime_char(*p) ) {
316 317
 			while(node!=-1 && !is_char_equal(*p,subtype_tree[node].c) )
317 318
 				node = subtype_tree[node].next;
318
-			if (node!=-1 && subtype_tree[node].nr_sons && (p < end - 1))
319
-				node++;
319
+			if (node!=-1) {
320
+				type_candidate = subtype_tree[node].final;
321
+				if (subtype_tree[node].nr_sons)
322
+        				node++;
323
+				else
324
+					node = -1;
325
+			} else {
326
+				/* end of the subtype tree has reached,
327
+				but the subtype has still some remaining
328
+				characters (Miklos) */
329
+				type_candidate = SUBTYPE_UNKNOWN;
330
+			}
320 331
 			p++;
321 332
 		}
322 333
 		if (p==mark)
323 334
 			goto error;
324
-		if (node!=-1)
325
-			*mime_type |= subtype_tree[node].final;
326
-		else
327
-			*mime_type |= SUBTYPE_UNKNOWN;
335
+		*mime_type |= type_candidate;;
328 336
 	}
329 337
 
330 338
 	/* now its possible to have some spaces */