Browse code

replace AC_MIN_LENGTH with cli_matcher->ac_depth

git-svn: trunk@1751

Tomasz Kojm authored on 2005/11/11 10:31:46
Showing 6 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri Nov 11 01:27:56 CET 2005 (tk)
2
+---------------------------------
3
+  * libclamav/matcher-ac.c: replace AC_MIN_LENGTH with cli_matcher->ac_depth
4
+
1 5
 Thu Nov 10 23:48:27 CET 2005 (tk)
2 6
 ---------------------------------
3 7
   * libclamav/others.c, clamav.h: remove cl_perror()
... ...
@@ -135,6 +135,7 @@ struct cli_matcher {
135 135
     struct cli_bm_patt **bm_suffix;
136 136
 
137 137
     /* Extended Aho-Corasick */
138
+    unsigned int ac_depth;
138 139
     struct cli_ac_node *ac_root, **ac_nodetable;
139 140
     unsigned int ac_partsigs, ac_nodes;
140 141
 };
... ...
@@ -30,6 +30,7 @@
30 30
 #include "filetypes.h"
31 31
 #include "others.h"
32 32
 #include "readdb.h"
33
+#include "matcher-ac.h"
33 34
 
34 35
 struct cli_magic_s {
35 36
     int offset;
... ...
@@ -285,6 +286,7 @@ int cli_addtypesigs(struct cl_engine *engine)
285 285
 	    cli_errmsg("cli_addtypesigs: Can't initialise AC pattern matcher\n");
286 286
 	    return CL_EMEM;
287 287
 	}
288
+	root->ac_depth = AC_DEFAULT_DEPTH;
288 289
 	root->ac_root =  (struct cli_ac_node *) cli_calloc(1, sizeof(struct cli_ac_node));
289 290
 	if(!root->ac_root) {
290 291
 	    cli_errmsg("cli_addtypesigs: Can't initialise AC pattern matcher\n");
... ...
@@ -37,8 +37,6 @@
37 37
 #include "defaults.h"
38 38
 #include "filetypes.h"
39 39
 
40
-#define AC_MIN_LENGTH 2
41
-
42 40
 struct nodelist {
43 41
     struct cli_ac_node *node;
44 42
     struct nodelist *next;
... ...
@@ -49,12 +47,12 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
49 49
 	struct cli_ac_node *pos, *next;
50 50
 	int i;
51 51
 
52
-    if(pattern->length < AC_MIN_LENGTH)
52
+    if(pattern->length < root->ac_depth)
53 53
 	return CL_EPATSHORT;
54 54
 
55 55
     pos = root->ac_root;
56 56
 
57
-    for(i = 0; i < AC_MIN_LENGTH; i++) {
57
+    for(i = 0; i < root->ac_depth; i++) {
58 58
 	next = pos->trans[((unsigned char) pattern->pattern[i]) & 0xff]; 
59 59
 
60 60
 	if(!next) {
... ...
@@ -223,17 +221,17 @@ void cli_ac_free(struct cli_matcher *root)
223 223
 	free(root->ac_root);
224 224
 }
225 225
 
226
-inline static int cli_findpos(const char *buffer, int offset, int length, const struct cli_ac_patt *pattern)
226
+inline static int cli_findpos(const char *buffer, unsigned int depth, unsigned int offset, unsigned int length, const struct cli_ac_patt *pattern)
227 227
 {
228
-	int bufferpos = offset + AC_MIN_LENGTH;
229
-	int postfixend = offset + length;
228
+	unsigned int bufferpos = offset + depth;
229
+	unsigned int postfixend = offset + length;
230 230
 	unsigned int i, j, alt = 0, found = 0;
231 231
 
232 232
 
233 233
     if(bufferpos >= length)
234 234
 	bufferpos %= length;
235 235
 
236
-    for(i = AC_MIN_LENGTH; i < pattern->length; i++) {
236
+    for(i = depth; i < pattern->length; i++) {
237 237
 
238 238
 	if(bufferpos == postfixend)
239 239
 	    return 0;
... ...
@@ -264,8 +262,8 @@ int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virnam
264 264
 {
265 265
 	struct cli_ac_node *current;
266 266
 	struct cli_ac_patt *pt;
267
-	int position, type = CL_CLEAN, dist, t;
268
-        unsigned int i;
267
+	int type = CL_CLEAN, dist, t;
268
+        unsigned int i, position;
269 269
 
270 270
 
271 271
     if(!root->ac_root)
... ...
@@ -282,11 +280,11 @@ int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virnam
282 282
 	current = current->trans[(unsigned char) buffer[i] & 0xff];
283 283
 
284 284
 	if(current->islast) {
285
-	    position = i - AC_MIN_LENGTH + 1;
285
+	    position = i - root->ac_depth + 1;
286 286
 
287 287
 	    pt = current->list;
288 288
 	    while(pt) {
289
-		if(cli_findpos(buffer, position, length, pt)) {
289
+		if(cli_findpos(buffer, root->ac_depth, position, length, pt)) {
290 290
 		    if((pt->offset || pt->target) && (!pt->sigid || pt->partno == 1)) {
291 291
 			if(ftype == CL_TYPE_UNKNOWN_TEXT)
292 292
 			    t = type;
... ...
@@ -22,6 +22,8 @@
22 22
 #include "clamav.h"
23 23
 #include "matcher.h"
24 24
 
25
+#define AC_DEFAULT_DEPTH 2
26
+
25 27
 int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern);
26 28
 int cli_ac_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cli_matcher *root, int *partcnt, short otfrec, unsigned long int offset, unsigned long int *partoff, unsigned short ftype, int fd, unsigned long int *ftoffset);
27 29
 int cli_ac_buildtrie(struct cli_matcher *root);
... ...
@@ -472,6 +472,7 @@ static int cli_initroots(struct cl_engine *engine)
472 472
 	    }
473 473
 
474 474
 	    cli_dbgmsg("Initialising AC pattern matcher of root[%d]\n", i);
475
+	    root->ac_depth = AC_DEFAULT_DEPTH;
475 476
 	    root->ac_root =  (struct cli_ac_node *) cli_calloc(1, sizeof(struct cli_ac_node));
476 477
 	    if(!root->ac_root) {
477 478
 		/* no need to free previously allocated memory here */