Browse code

libclamav/matcher-ac.c: improve negation of single elements - handle !(xx) (bb#4052)

Tomasz Kojm authored on 2011/12/16 05:41:51
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Thu Dec 15 21:40:57 CET 2011 (tk)
2
+---------------------------------
3
+ * libclamav/matcher-ac.c: improve negation of single elements - handle
4
+			   !(xx) (bb#4052)
5
+
1 6
 Thu Dec 15 18:34:03 EET 2011 (edwin)
2 7
 ------------------------------------
3 8
  * libclamav/pdf.c: scan inside encrypted PDF streams and strings when user
... ...
@@ -1646,16 +1646,11 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1646 1646
 		newspecial->type = AC_SPECIAL_WHITE;
1647 1647
 	    */
1648 1648
 	    } else {
1649
+		newspecial->num = 1;
1649 1650
 		for(i = 0; i < strlen(pt); i++)
1650 1651
 		    if(pt[i] == '|')
1651 1652
 			newspecial->num++;
1652 1653
 
1653
-		if(!newspecial->num) {
1654
-		    error = CL_EMALFDB;
1655
-		    break;
1656
-		} else
1657
-		    newspecial->num++;
1658
-
1659 1654
 		if(3 * newspecial->num - 1 == (uint16_t) strlen(pt)) {
1660 1655
 		    newspecial->type = AC_SPECIAL_ALT_CHAR;
1661 1656
 		    newspecial->str = (unsigned char *) mpool_malloc(root->mempool, newspecial->num);
... ...
@@ -1669,13 +1664,21 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1669 1669
 		}
1670 1670
 
1671 1671
 		for(i = 0; i < newspecial->num; i++) {
1672
-		    if(!(h = cli_strtok(pt, i, "|"))) {
1673
-			error = CL_EMALFDB;
1674
-			break;
1675
-		    }
1672
+			unsigned int clen;
1676 1673
 
1677
-		    if(!(c = (char*)cli_mpool_hex2str(root->mempool, h))) {
1674
+		    if(newspecial->num == 1) {
1675
+			c = (char *) cli_mpool_hex2str(root->mempool, pt);
1676
+			clen = strlen(pt) / 2;
1677
+		    } else {
1678
+			if(!(h = cli_strtok(pt, i, "|"))) {
1679
+			    error = CL_EMEM;
1680
+			    break;
1681
+			}
1682
+			c = (char *) cli_mpool_hex2str(root->mempool, h);
1683
+			clen = strlen(h) / 2;
1678 1684
 			free(h);
1685
+		    }
1686
+		    if(!c) {
1679 1687
 			error = CL_EMALFDB;
1680 1688
 			break;
1681 1689
 		    }
... ...
@@ -1694,19 +1697,17 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1694 1694
 				cli_errmsg("cli_ac_addsig: Can't allocate specialpt->next\n");
1695 1695
 				error = CL_EMEM;
1696 1696
 				free(c);
1697
-				free(h);
1698 1697
 				break;
1699 1698
 			    }
1700 1699
 			    specialpt->next->str = (unsigned char *) c;
1701
-			    specialpt->next->len = strlen(h) / 2;
1700
+			    specialpt->next->len = clen;
1702 1701
 			} else {
1703 1702
 			    newspecial->str = (unsigned char *) c;
1704
-			    newspecial->len = strlen(h) / 2;
1703
+			    newspecial->len = clen;
1705 1704
 			}
1706 1705
 		    }
1707
-		    free(h);
1708 1706
 		}
1709
-		if(newspecial->type == AC_SPECIAL_ALT_CHAR)
1707
+		if(newspecial->num > 1 && newspecial->type == AC_SPECIAL_ALT_CHAR)
1710 1708
 		    cli_qsort(newspecial->str, newspecial->num, sizeof(unsigned char), qcompare);
1711 1709
 
1712 1710
 		if(error)