... | ... |
@@ -79,23 +79,33 @@ static char boundary[256] = { |
79 | 79 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
80 | 80 |
}; |
81 | 81 |
|
82 |
-static inline int insert_pattlist(mpool_t *mempool, struct cli_ac_patt *pattern, struct cli_ac_node *pt) |
|
82 |
+static inline int insert_list(struct cli_matcher *root, struct cli_ac_patt *pattern, struct cli_ac_node *pt) |
|
83 | 83 |
{ |
84 |
- struct cli_ac_pattlist *ph, *new, *ph_prev, *ph_add_after; |
|
84 |
+ struct cli_ac_list *ph, *new, *ph_prev, *ph_add_after; |
|
85 |
+ struct cli_ac_list **newtable; |
|
85 | 86 |
struct cli_ac_patt *php; |
86 | 87 |
struct cli_ac_special *a1, *a2; |
87 | 88 |
uint8_t i, match; |
88 | 89 |
|
89 |
- if (mempool) |
|
90 |
- new = (struct cli_ac_pattlist *)mpool_calloc(mempool, 1, sizeof(struct cli_ac_pattlist)); |
|
91 |
- else |
|
92 |
- new = cli_calloc(1, sizeof(struct cli_ac_pattlist)); |
|
90 |
+ new = (struct cli_ac_list *)mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_list)); |
|
93 | 91 |
if (!new) { |
94 |
- cli_errmsg("cli_ac_addpatt: Can't allocate memory for pattlist node\n"); |
|
92 |
+ cli_errmsg("cli_ac_addpatt: Can't allocate memory for list node\n"); |
|
95 | 93 |
return CL_EMEM; |
96 | 94 |
} |
97 | 95 |
new->me = pattern; |
98 | 96 |
|
97 |
+ root->ac_lists++; |
|
98 |
+ newtable = mpool_realloc(root->mempool, root->ac_listtable, root->ac_lists * sizeof(struct cli_ac_list *)); |
|
99 |
+ if(!newtable) { |
|
100 |
+ root->ac_lists--; |
|
101 |
+ cli_errmsg("cli_ac_addpatt: Can't realloc ac_listtable\n"); |
|
102 |
+ mpool_free(root->mempool, new); |
|
103 |
+ return CL_EMEM; |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ root->ac_listtable = newtable; |
|
107 |
+ root->ac_listtable[root->ac_lists - 1] = new; |
|
108 |
+ |
|
99 | 109 |
ph = pt->list; |
100 | 110 |
ph_add_after = ph_prev = NULL; |
101 | 111 |
while(ph) { |
... | ... |
@@ -230,7 +240,7 @@ static int cli_ac_addpatt_recursive(struct cli_matcher *root, struct cli_ac_patt |
230 | 230 |
|
231 | 231 |
/* last node, insert pattern here (base case)*/ |
232 | 232 |
if(i >= len) { |
233 |
- return insert_pattlist(root->mempool, pattern, pt); |
|
233 |
+ return insert_list(root, pattern, pt); |
|
234 | 234 |
} |
235 | 235 |
|
236 | 236 |
/* if current node has no trans table, generate one */ |
... | ... |
@@ -422,7 +432,7 @@ static int ac_maketrans(struct cli_matcher *root) |
422 | 422 |
failtarget = failtarget->trans[i]; |
423 | 423 |
node->trans[i] = failtarget; |
424 | 424 |
} else if (IS_FINAL(child) && IS_LEAF(child)) { |
425 |
- struct cli_ac_pattlist *list; |
|
425 |
+ struct cli_ac_list *list; |
|
426 | 426 |
|
427 | 427 |
list = child->list; |
428 | 428 |
if (list) { |
... | ... |
@@ -555,7 +565,11 @@ void cli_ac_free(struct cli_matcher *root) |
555 | 555 |
} |
556 | 556 |
} |
557 | 557 |
|
558 |
- /* TODO - free the pattlists somewhere! */ |
|
558 |
+ for(i = 0; i < root->ac_lists; i++) |
|
559 |
+ mpool_free(root->mempool, root->ac_listtable[i]); |
|
560 |
+ |
|
561 |
+ if(root->ac_listtable) |
|
562 |
+ mpool_free(root->mempool, root->ac_listtable); |
|
559 | 563 |
|
560 | 564 |
for(i = 0; i < root->ac_nodes; i++) |
561 | 565 |
mpool_free(root->mempool, root->ac_nodetable[i]); |
... | ... |
@@ -1293,7 +1307,7 @@ void cli_ac_chkmacro(struct cli_matcher *root, struct cli_ac_data *data, unsigne |
1293 | 1293 |
int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, void **customdata, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, uint32_t offset, cli_file_t ftype, struct cli_matched_type **ftoffset, unsigned int mode, cli_ctx *ctx) |
1294 | 1294 |
{ |
1295 | 1295 |
struct cli_ac_node *current; |
1296 |
- struct cli_ac_pattlist *pattN, *ptN; |
|
1296 |
+ struct cli_ac_list *pattN, *ptN; |
|
1297 | 1297 |
struct cli_ac_patt *patt, *pt; |
1298 | 1298 |
uint32_t i, bp, realoff, matchend; |
1299 | 1299 |
uint16_t j; |
... | ... |
@@ -1316,7 +1330,7 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v |
1316 | 1316 |
current = current->trans[buffer[i]]; |
1317 | 1317 |
|
1318 | 1318 |
if(UNLIKELY(IS_FINAL(current))) { |
1319 |
- struct cli_ac_pattlist *faillist = current->fail->list; |
|
1319 |
+ struct cli_ac_list *faillist = current->fail->list; |
|
1320 | 1320 |
pattN = current->list; |
1321 | 1321 |
while(pattN) { |
1322 | 1322 |
patt = pattN->me; |
... | ... |
@@ -76,13 +76,13 @@ struct cli_ac_patt { |
76 | 76 |
uint8_t nocase; |
77 | 77 |
}; |
78 | 78 |
|
79 |
-struct cli_ac_pattlist { |
|
79 |
+struct cli_ac_list { |
|
80 | 80 |
struct cli_ac_patt *me; |
81 |
- struct cli_ac_pattlist *next, *next_same; |
|
81 |
+ struct cli_ac_list *next, *next_same; |
|
82 | 82 |
}; |
83 | 83 |
|
84 | 84 |
struct cli_ac_node { |
85 |
- struct cli_ac_pattlist *list; |
|
85 |
+ struct cli_ac_list *list; |
|
86 | 86 |
struct cli_ac_node **trans, *fail; |
87 | 87 |
}; |
88 | 88 |
|
... | ... |
@@ -100,9 +100,10 @@ struct cli_matcher { |
100 | 100 |
struct cli_hash_wild hwild; |
101 | 101 |
|
102 | 102 |
/* Extended Aho-Corasick */ |
103 |
- uint32_t ac_partsigs, ac_nodes, ac_patterns, ac_lsigs; |
|
103 |
+ uint32_t ac_partsigs, ac_nodes, ac_lists, ac_patterns, ac_lsigs; |
|
104 | 104 |
struct cli_ac_lsig **ac_lsigtable; |
105 | 105 |
struct cli_ac_node *ac_root, **ac_nodetable; |
106 |
+ struct cli_ac_list **ac_listtable; |
|
106 | 107 |
struct cli_ac_patt **ac_pattable; |
107 | 108 |
struct cli_ac_patt **ac_reloff; |
108 | 109 |
uint32_t ac_reloff_num, ac_absoff_num; |