Browse code

Fix handling of string alternates (bb #2004).

Török Edvin authored on 2010/05/12 03:34:18
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue May 11 21:33:49 EEST 2010 (edwin)
2
+-------------------------------------
3
+ * libclamav/filtering.c: fix handling of alternates and negated alternates (bb #2004)
4
+
1 5
 Tue May 11 15:31:40 EEST 2010 (edwin)
2 6
 -------------------------------------
3 7
  * libclamav/readdb.c: read the entire .cbc files, fix loading of bytecode.cvd
... ...
@@ -439,6 +439,7 @@ int  filter_add_acpatt(struct filter *m, const struct cli_ac_patt *pat)
439 439
 	struct choice choices[MAX_CHOICES];
440 440
 	unsigned choices_cnt = 0;
441 441
 	unsigned prefix_len = pat->prefix_length;
442
+	unsigned speci;
442 443
 
443 444
 	j = MIN(prefix_len + pat->length, MAXPATLEN);
444 445
 	for(i=0;i<j;i++) {
... ...
@@ -453,9 +454,19 @@ int  filter_add_acpatt(struct filter *m, const struct cli_ac_patt *pat)
453 453
 		return filter_add_static(m, patc, j, pat->virname);
454 454
 	}
455 455
 	cli_perf_log_count(TRIE_ORIG_LEN, j > 8 ? 8 : j);
456
+	i = 0;
457
+	if (!prefix_len) {
458
+	    while ((pat->pattern[i] & CLI_MATCH_WILDCARD) == CLI_MATCH_SPECIAL) {
459
+		/* we support only ALT_CHAR, skip the rest */
460
+		if (pat->special_table[altcnt]->type == 1)
461
+		    break;
462
+		altcnt++;
463
+		i++;
464
+	    }
465
+	}
456 466
 	/* transform AC characters into our representation */
457
-	for (i=0;i<j && !stop; i++) {
458
-		struct char_spec *spec = &chars[i];
467
+	for (speci=0;i<j && !stop; speci++,i++) {
468
+		struct char_spec *spec = &chars[speci];
459 469
 		const uint16_t p = i < prefix_len ? pat->prefix[i] : pat->pattern[i - prefix_len];
460 470
 		spec->alt = NULL;
461 471
 		spec->negative = 0;
... ...
@@ -502,8 +513,8 @@ int  filter_add_acpatt(struct filter *m, const struct cli_ac_patt *pat)
502 502
 				return -1;
503 503
 		}
504 504
 	}
505
-	if (stop) --i;
506
-	j = i;
505
+	if (stop) --speci;
506
+	j = speci;
507 507
 	if (j < 2) {
508 508
 		if (stop)
509 509
 			cli_warnmsg("Don't know how to create filter for: %s\n",pat->virname);