git-svn: trunk@2304
aCaB authored on 2006/09/25 04:28:03... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Sun Sep 24 21:24:07 CEST 2006 (acab) |
|
2 |
+------------------------------------ |
|
3 |
+ * libclamav/regex_list.c: fixes for type "R" regex handler |
|
4 |
+ (patch from Edvin) |
|
5 |
+ |
|
1 | 6 |
Fri Sep 22 23:42:09 CEST 2006 (tk) |
2 | 7 |
---------------------------------- |
3 | 8 |
* libclamav/others.c: improve error handling in cli_rmdirs() |
... | ... |
@@ -19,6 +19,9 @@ |
19 | 19 |
* MA 02110-1301, USA. |
20 | 20 |
* |
21 | 21 |
* $Log: regex_list.c,v $ |
22 |
+ * Revision 1.3 2006/09/24 19:28:03 acab |
|
23 |
+ * fixes for type "R" regex handler |
|
24 |
+ * |
|
22 | 25 |
* Revision 1.2 2006/09/16 15:49:27 acab |
23 | 26 |
* phishing: fixed bugs and updated docs |
24 | 27 |
* |
... | ... |
@@ -748,10 +751,12 @@ static const unsigned char* getNextToken(const unsigned char* pat,struct token_t |
748 | 748 |
token->u.start = ++pat; |
749 | 749 |
if(islower(*token->u.start)) { |
750 | 750 |
/* handle \n, \t, etc. */ |
751 |
+ char fmt[3] = {'\\',*token->u.start,'\0'}; |
|
751 | 752 |
char c; |
752 |
- if(snprintf(&c,1,"\%c",token->u.start)!=1) |
|
753 |
+ if(snprintf(&c,1,fmt)!=1) |
|
753 | 754 |
token->type=TOKEN_REGEX; |
754 |
- token->u.start=c; |
|
755 |
+ else |
|
756 |
+ *token->u.start=c; |
|
755 | 757 |
} |
756 | 758 |
token->len = 1; |
757 | 759 |
break; |
... | ... |
@@ -1058,9 +1063,21 @@ static inline void tree_node_insert_nonbin(struct tree_node* node, struct tree_n |
1058 | 1058 |
} |
1059 | 1059 |
} |
1060 | 1060 |
else { |
1061 |
- node->u.children = cli_realloc(node->u.children,sizeof(node->u.children[0])*( node->op==OP_CUSTOMCLASS ? 2 : 1 )); |
|
1061 |
+ int idx = node->op==OP_CUSTOMCLASS ? 1 : 0; |
|
1062 | 1062 |
if(node->u.children) |
1063 |
- node->u.children[ node->op==OP_CUSTOMCLASS ? 1 : 0 ] = new; |
|
1063 |
+ if(node->u.children[idx]) { |
|
1064 |
+ node = node->u.children[idx]; |
|
1065 |
+ while(node->next && !node->listend) |
|
1066 |
+ node = node->next; |
|
1067 |
+ node->listend = 0; |
|
1068 |
+ node->next = new; |
|
1069 |
+ new->listend=1; |
|
1070 |
+ return; |
|
1071 |
+ } |
|
1072 |
+ node->u.children = cli_realloc(node->u.children,sizeof(node->u.children[0])*(2)); |
|
1073 |
+ if(node->u.children) { |
|
1074 |
+ node->u.children[idx] = new; |
|
1075 |
+ } |
|
1064 | 1076 |
} |
1065 | 1077 |
} |
1066 | 1078 |
|
... | ... |
@@ -1202,13 +1219,13 @@ static int add_pattern(struct regex_matcher* matcher,const unsigned char* pat,co |
1202 | 1202 |
case TOKEN_REGEX: |
1203 | 1203 |
case TOKEN_DONE: { |
1204 | 1204 |
struct leaf_info* leaf=cli_malloc(sizeof(*leaf)); |
1205 |
- leaf->info=strdup(info); |
|
1205 |
+ leaf->info=info;/*don't strdup, already done by caller*/ |
|
1206 | 1206 |
if(token.type==TOKEN_REGEX) { |
1207 | 1207 |
int rc; |
1208 | 1208 |
struct tree_node* new; |
1209 | 1209 |
regex_t* preg; |
1210 | 1210 |
preg=cli_malloc(sizeof(*preg)); |
1211 |
- rc = regcomp(preg,(const char*)token.u.start,bol?0:REG_NOTBOL); |
|
1211 |
+ rc = regcomp(preg,(const char*)token.u.start,REG_EXTENDED|(bol?0:REG_NOTBOL)); |
|
1212 | 1212 |
leaf->preg=preg; |
1213 | 1213 |
if(rc) |
1214 | 1214 |
return rc; |
... | ... |
@@ -1369,7 +1386,11 @@ static int match_node(struct tree_node* node,const unsigned char* c,size_t len,c |
1369 | 1369 |
} |
1370 | 1370 |
if(!node || !node->next) /* reached root node, it has no next */ |
1371 | 1371 |
return MATCH_FAILED; |
1372 |
- else node=node->next; |
|
1372 |
+ else { |
|
1373 |
+ c--; |
|
1374 |
+ len++; |
|
1375 |
+ node=node->next; |
|
1376 |
+ } |
|
1373 | 1377 |
} |
1374 | 1378 |
} |
1375 | 1379 |
return MATCH_FAILED; |
... | ... |
@@ -1428,7 +1449,7 @@ static void destroy_tree_internal(struct regex_matcher* matcher,struct tree_node |
1428 | 1428 |
destroy_tree_internal(matcher,children[0]); |
1429 | 1429 |
} |
1430 | 1430 |
} |
1431 |
- if(node->next && !node->listend) |
|
1431 |
+ if(node->op!=OP_LEAF && node->next && !node->listend) |
|
1432 | 1432 |
destroy_tree_internal(matcher,node->next); |
1433 | 1433 |
if(node->u.children) |
1434 | 1434 |
stack_push_once(&matcher->node_stack,(struct tree_node*)node->u.children);/* cast to make compiler happy, it isn't really a tree_node* */ |