Browse code

initialise AC matcher in engine->root[0] if needed

git-svn: trunk@1733

Tomasz Kojm authored on 2005/10/20 07:57:36
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Thu Oct 20 00:54:13 CEST 2005 (tk)
2
+----------------------------------
3
+  * libclamav/filetypes.c: cli_addtypesigs: initialise AC matcher in
4
+			   engine->root[0] if needed
5
+
1 6
 Tue Oct 18 11:29:04 BST 2005 (trog)
2 7
 -----------------------------------
3 8
   * libclamav/others.c,h: Add generic bitset implementation
... ...
@@ -277,11 +277,29 @@ int cli_addtypesigs(struct cl_engine *engine)
277 277
 	int i, ret;
278 278
 	struct cli_matcher *root;
279 279
 
280
-    root = engine->root[0];
280
+
281
+    if(!engine->root[0]) {
282
+	cli_dbgmsg("cli_addtypesigs: Need to allocate AC trie in engine->root[0]\n");
283
+	root = engine->root[0] = (struct cli_matcher *) cli_calloc(1, sizeof(struct cli_matcher));
284
+	if(!root) {
285
+	    cli_errmsg("cli_addtypesigs: Can't initialise AC pattern matcher\n");
286
+	    return CL_EMEM;
287
+	}
288
+	root->ac_root =  (struct cli_ac_node *) cli_calloc(1, sizeof(struct cli_ac_node));
289
+	if(!root->ac_root) {
290
+	    cli_errmsg("cli_addtypesigs: Can't initialise AC pattern matcher\n");
291
+	    /* No need to free previously allocated memory here - all engine
292
+	     * elements will be properly freed by cl_free()
293
+	     */
294
+	    return CL_EMEM;
295
+	}
296
+    } else {
297
+	root = engine->root[0];
298
+    }
281 299
 
282 300
     for(i = 0; cli_smagic[i].sig; i++) {
283 301
 	if((ret = cli_parse_add(root, cli_smagic[i].descr, cli_smagic[i].sig, cli_smagic[i].type, NULL, 0))) {
284
-	    cli_errmsg("cli_addtypesigs(): Problem adding signature for %s\n", cli_smagic[i].descr);
302
+	    cli_errmsg("cli_addtypesigs: Problem adding signature for %s\n", cli_smagic[i].descr);
285 303
 	    return ret;
286 304
 	}
287 305
     }