Browse code

Merge branch 'prefiltering_split' into prefiltering3

* prefiltering_split:
move matching code to matcher_run.
matcher-ac: move leaf checks inside IS_FINAL.

Conflicts:
libclamav/matcher.c

Török Edvin authored on 2010/02/10 03:19:56
Showing 2 changed files
... ...
@@ -333,7 +333,7 @@ static int ac_maketrans(struct cli_matcher *root)
333 333
 	    continue;
334 334
 	for(i = 0; i < 256; i++) {
335 335
 	    child = node->trans[i];
336
-	    if(!child) {
336
+	    if (!child || (!IS_FINAL(child) && IS_LEAF(child))) {
337 337
 		struct cli_ac_node *failtarget = node->fail;
338 338
 		while(IS_LEAF(failtarget) || !failtarget->trans[i])
339 339
 		    failtarget = failtarget->fail;
... ...
@@ -1132,14 +1132,12 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1132 1132
     current = root->ac_root;
1133 1133
 
1134 1134
     for(i = 0; i < length; i++)  {
1135
-
1136
-	if(IS_LEAF(current))
1137
-	    current = current->fail;
1138
-
1139 1135
 	current = current->trans[buffer[i]];
1140 1136
 
1141 1137
 	if(IS_FINAL(current)) {
1142 1138
 	    patt = current->list;
1139
+	    if (IS_LEAF(current))
1140
+		current = current->fail;
1143 1141
 	    while(patt) {
1144 1142
 		bp = i + 1 - patt->depth;
1145 1143
 		if(patt->offdata[0] != CLI_OFF_VERSION && patt->offdata[0] != CLI_OFF_MACRO && !patt->next_same && (patt->offset_min != CLI_OFF_ANY) && (!patt->sigid || patt->partno == 1)) {
... ...
@@ -49,6 +49,22 @@
49 49
 #include "pe_icons.h"
50 50
 #include "regex/regex.h"
51 51
 
52
+static inline int matcher_run(const struct cli_matcher *root,
53
+			      const unsigned char *buffer, uint32_t length,
54
+			      const char **virname, struct cli_ac_data *mdata,
55
+			      uint32_t offset,
56
+			      cli_file_t ftype,
57
+			      struct cli_matched_type **ftoffset,
58
+			      unsigned int acmode,
59
+			      fmap_t *map,
60
+			      struct cli_bm_off *offdata)
61
+{
62
+    int ret;
63
+    if (root->ac_only || (ret = cli_bm_scanbuff(buffer, length, virname, NULL, root, offset, map, offdata)) != CL_VIRUS)
64
+	ret = cli_ac_scanbuff(buffer, length, virname, NULL, NULL, root, mdata, offset, ftype, ftoffset, acmode, NULL);
65
+    return ret;
66
+}
67
+
52 68
 int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset, cli_ctx *ctx, cli_file_t ftype, struct cli_ac_data **acdata)
53 69
 {
54 70
 	int ret = CL_CLEAN;
... ...
@@ -79,8 +95,7 @@ int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset,
79 79
 	if(!acdata && (ret = cli_ac_initdata(&mdata, troot->ac_partsigs, troot->ac_lsigs, troot->ac_reloff_num, CLI_DEFAULT_AC_TRACKLEN)))
80 80
 	    return ret;
81 81
 
82
-	if(troot->ac_only || (ret = cli_bm_scanbuff(buffer, length, virname, NULL, troot, offset, NULL, NULL)) != CL_VIRUS)
83
-	    ret = cli_ac_scanbuff(buffer, length, virname, NULL, NULL, troot, acdata ? (acdata[0]) : (&mdata), offset, ftype, NULL, AC_SCAN_VIR, NULL);
82
+	ret = matcher_run(troot, buffer, length, virname, acdata ? (acdata[0]): (&mdata), offset, ftype, NULL, AC_SCAN_VIR, NULL, NULL);
84 83
 
85 84
 	if(!acdata)
86 85
 	    cli_ac_freedata(&mdata);
... ...
@@ -92,8 +107,7 @@ int cli_scanbuff(const unsigned char *buffer, uint32_t length, uint32_t offset,
92 92
     if(!acdata && (ret = cli_ac_initdata(&mdata, groot->ac_partsigs, groot->ac_lsigs, groot->ac_reloff_num, CLI_DEFAULT_AC_TRACKLEN)))
93 93
 	return ret;
94 94
 
95
-    if(groot->ac_only || (ret = cli_bm_scanbuff(buffer, length, virname, NULL, groot, offset, NULL, NULL)) != CL_VIRUS)
96
-	ret = cli_ac_scanbuff(buffer, length, virname, NULL, NULL, groot, acdata ? (acdata[1]) : (&mdata), offset, ftype, NULL, AC_SCAN_VIR, NULL);
95
+    ret = matcher_run(groot, buffer, length, virname, acdata ? (acdata[1]): (&mdata), offset, ftype, NULL, AC_SCAN_VIR, NULL, NULL);
97 96
 
98 97
     if(!acdata)
99 98
 	cli_ac_freedata(&mdata);
... ...
@@ -444,8 +458,8 @@ int cli_fmap_scandesc(cli_ctx *ctx, cli_file_t ftype, uint8_t ftonly, struct cli
444 444
 	    *ctx->scanned += bytes / CL_COUNT_PRECISION;
445 445
 
446 446
 	if(troot) {
447
-	    if(troot->ac_only || (ret = cli_bm_scanbuff(buff, bytes, ctx->virname, NULL, troot, offset, map, bm_offmode ? &toff : NULL)) != CL_VIRUS)
448
-		ret = cli_ac_scanbuff(buff, bytes, ctx->virname, NULL, NULL, troot, &tdata, offset, ftype, ftoffset, acmode, NULL);
447
+	    ret = matcher_run(troot, buff, bytes, ctx->virname, &tdata, offset, ftype, ftoffset, acmode, map, bm_offmode ? &toff : NULL);
448
+
449 449
 	    if(ret == CL_VIRUS) {
450 450
 		if(!ftonly)
451 451
 		    cli_ac_freedata(&gdata);