Browse code

libclamav: optimize handling of {n} wildcards (bb#1796)

Tomasz Kojm authored on 2011/03/10 23:55:13
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Mar 10 15:54:05 CET 2011 (tk)
2
+---------------------------------
3
+ * libclamav: optimize handling of {n} wildcards (bb#1796)
4
+
1 5
 Wed Mar  9 15:42:50 CET 2011 (tk)
2 6
 ---------------------------------
3 7
  * clamdscan: fix file exclusion (bb#2579)
... ...
@@ -112,8 +112,9 @@ char *cli_virname(char *virname, unsigned int official)
112 112
 int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hexsig, uint16_t rtype, uint16_t type, const char *offset, uint8_t target, const uint32_t *lsigid, unsigned int options)
113 113
 {
114 114
 	struct cli_bm_patt *bm_new;
115
-	char *pt, *hexcpy, *start, *n;
116
-	int ret, asterisk = 0;
115
+	char *pt, *hexcpy, *start, *n, l, r;
116
+	const char *wild;
117
+	int ret, asterisk = 0, range;
117 118
 	unsigned int i, j, hexlen, parts = 0;
118 119
 	int mindist = 0, maxdist = 0, error = 0;
119 120
 
... ...
@@ -162,7 +163,24 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
162 162
 	}
163 163
 	return CL_SUCCESS;
164 164
     }
165
-    if(strchr(hexsig, '{')) {
165
+    if((wild = strchr(hexsig, '{'))) {
166
+	if(sscanf(wild, "%c%u%c", &l, &range, &r) == 3 && l == '{' && r == '}' && range > 0 && range < 128) {
167
+	    hexcpy = cli_calloc(hexlen + 2 * range, sizeof(char));
168
+	    if(!hexcpy)
169
+		return CL_EMEM;
170
+	    strncpy(hexcpy, hexsig, wild - hexsig);
171
+	    for(i = 0; i < (unsigned int) range; i++)
172
+		strcat(hexcpy, "??");
173
+	    if(!(wild = strchr(wild, '}'))) {
174
+		cli_errmsg("cli_parse_add(): Problem adding signature: missing bracket\n");
175
+		free(hexcpy);
176
+		return CL_EMALFDB;
177
+	    }
178
+	    strcat(hexcpy, ++wild);
179
+	    ret = cli_parse_add(root, virname, hexcpy, rtype, type, offset, target, lsigid, options);
180
+	    free(hexcpy);
181
+	    return ret;
182
+	}
166 183
 
167 184
 	root->ac_partsigs++;
168 185