Browse code

fix range calculation for multipart sigs with string alternatives

git-svn: trunk@3266

Tomasz Kojm authored on 2007/10/04 22:56:48
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Thu Oct  4 15:16:45 CEST 2007 (tk)
2
+----------------------------------
3
+  * libclamav/matcher-ac.c: fix range calculation for multipart sigs with string
4
+			    alternatives
5
+
1 6
 Thu Oct  4 13:29:02 CEST 2007 (tk)
2 7
 ----------------------------------
3 8
   * freshclam/manager.c: downgrade "file not found on remote server" to warning
... ...
@@ -427,7 +427,7 @@ void cli_ac_free(struct cli_matcher *root)
427 427
 	    return 0;							\
428 428
     }
429 429
 
430
-inline static int ac_findmatch(const unsigned char *buffer, uint32_t offset, uint32_t length, const struct cli_ac_patt *pattern)
430
+inline static int ac_findmatch(const unsigned char *buffer, uint32_t offset, uint32_t length, const struct cli_ac_patt *pattern, uint32_t *end)
431 431
 {
432 432
 	uint32_t bp;
433 433
 	uint16_t wc, i, j, altcnt = pattern->alt_pattern;
... ...
@@ -440,10 +440,11 @@ inline static int ac_findmatch(const unsigned char *buffer, uint32_t offset, uin
440 440
 
441 441
     bp = offset + pattern->depth;
442 442
 
443
-    for(i = pattern->depth; i < pattern->length; i++) {
443
+    for(i = pattern->depth; i < pattern->length && bp < length; i++) {
444 444
 	AC_MATCH_CHAR(pattern->pattern[i],buffer[bp]);
445 445
 	bp++;
446 446
     }
447
+    *end = bp;
447 448
 
448 449
     if(pattern->prefix) {
449 450
 	altcnt = 0;
... ...
@@ -529,7 +530,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
529 529
 {
530 530
 	struct cli_ac_node *current;
531 531
 	struct cli_ac_patt *patt, *pt;
532
-        uint32_t i, bp, realoff;
532
+        uint32_t i, bp, realoff, matchend;
533 533
 	uint16_t j;
534 534
 	int32_t **offmatrix;
535 535
 	uint8_t found;
... ...
@@ -559,7 +560,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
559 559
 	    patt = current->list;
560 560
 	    while(patt) {
561 561
 		bp = i + 1 - patt->depth;
562
-		if(ac_findmatch(buffer, bp, length, patt)) {
562
+		if(ac_findmatch(buffer, bp, length, patt, &matchend)) {
563 563
 		    pt = patt;
564 564
 		    while(pt) {
565 565
 			realoff = offset + bp - pt->prefix_length;
... ...
@@ -621,8 +622,8 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
621 621
 			    if(pt->partno == 1 || (found && (pt->partno != pt->parts))) {
622 622
 				offmatrix[pt->partno - 1][0] %= AC_DEFAULT_TRACKLEN;
623 623
 				offmatrix[pt->partno - 1][0]++;
624
+				offmatrix[pt->partno - 1][offmatrix[pt->partno - 1][0]] = offset + matchend;
624 625
 
625
-				offmatrix[pt->partno - 1][offmatrix[pt->partno - 1][0]] = realoff + pt->length + pt->prefix_length;
626 626
 				if(pt->partno == 1) /* save realoff for the first part */
627 627
 				    offmatrix[pt->parts - 1][offmatrix[pt->partno - 1][0]] = realoff;
628 628
 			    } else if(found && pt->partno == pt->parts) {