]> source.dussan.org Git - rspamd.git/commitdiff
* Fix bug in expressions parser and optimizer
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 24 Mar 2009 16:47:10 +0000 (19:47 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 24 Mar 2009 16:47:10 +0000 (19:47 +0300)
src/expressions.c
src/plugins/regexp.c

index f222ea2b405ab0105d0bdbdd1d557974224c2c25..b115eba723a7edb18789bdbeb8bb4077dd2c44ff 100644 (file)
@@ -342,16 +342,13 @@ parse_expression (memory_pool_t *pool, char *line)
                                break;
 
                        case READ_FUNCTION:
-                               if (func == NULL) {
-                                       func = memory_pool_alloc (pool, sizeof (struct expression_function));
-                               }
-
                                if (*p == '/') {
                                        /* In fact it is regexp */
                                        state = READ_REGEXP;
                                        c ++;
                                        p ++;
                                } else if (*p == '(') {
+                                       func = memory_pool_alloc (pool, sizeof (struct expression_function));
                                        func->name = memory_pool_alloc (pool, p - c + 1);
                                        func->args = NULL;
                                        g_strlcpy (func->name, c, (p - c + 1));
index 53c64d2b396474fd0ccb8303abf892c2b7220eb7..e9c4ca7bf58bd2bd61462ae5ab6ba8a9a9a60ab9 100644 (file)
@@ -268,13 +268,13 @@ static gboolean
 optimize_regexp_expression (struct expression **e, GQueue *stack, gboolean res)
 {
        struct expression *it = *e;
-       gboolean ret = FALSE;
+       gboolean ret = FALSE, is_nearest = TRUE;
        
        while (it) {
                /* Find first operation for this iterator */
                if (it->type == EXPR_OPERATION) {
                        /* If this operation is just ! just inverse res and check for further operators */
-                       if (it->content.operation == '!') {
+                       if (it->content.operation == '!' && is_nearest) {
                                res = !res;
                                it = it->next;
                                *e = it;
@@ -290,6 +290,7 @@ optimize_regexp_expression (struct expression **e, GQueue *stack, gboolean res)
                        }
                        break;
                }
+               is_nearest = FALSE;
                it = it->next;
        }