Browse code

properly handle alternatives in the new approach

git-svn: trunk@3227

Tomasz Kojm authored on 2007/09/19 03:37:48
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Sep 18 19:50:33 CEST 2007 (tk)
2
+----------------------------------
3
+  * libclamav/matcher-ac.c: properly handle alternatives in the new approach
4
+
1 5
 Tue Sep 18 13:45:34 BST 2007 (njh)
2 6
 ----------------------------------
3 7
  * libclamav/regex/regcomp.c:	Fix compilation error on systems without
... ...
@@ -40,7 +40,7 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
40 40
 {
41 41
 	struct cli_ac_node *pt, *next, **newtable;
42 42
 	struct cli_ac_patt *ph;
43
-	uint8_t i;
43
+	uint8_t i, match;
44 44
 	uint16_t len = MIN(root->ac_maxdepth, pattern->length);
45 45
 
46 46
 
... ...
@@ -120,9 +120,25 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
120 120
     while(ph) {
121 121
 	if((ph->length == pattern->length) && (ph->prefix_length == pattern->prefix_length)) {
122 122
 	    if(!memcmp(ph->pattern, pattern->pattern, ph->length * sizeof(uint16_t)) && !memcmp(ph->prefix, pattern->prefix, ph->prefix_length * sizeof(uint16_t))) {
123
-		pattern->next_same = ph->next_same;
124
-		ph->next_same = pattern;
125
-		return CL_SUCCESS;
123
+		if(!ph->alt && !pattern->alt) {
124
+		    match = 1;
125
+		} else if(ph->alt == pattern->alt) {
126
+		    match = 1;
127
+		    for(i = 0; i < ph->alt; i++) {
128
+			if((ph->altn[i] != pattern->altn[i]) || memcmp(ph->altc[i], pattern->altc[i], ph->altn[i])) {
129
+			    match = 0;
130
+			    break;
131
+			}
132
+		    }
133
+		} else {
134
+		    match = 0;
135
+		}
136
+
137
+		if(match) {
138
+		    pattern->next_same = ph->next_same;
139
+		    ph->next_same = pattern;
140
+		    return CL_SUCCESS;
141
+		}
126 142
 	    }
127 143
 	}
128 144
 	ph = ph->next;