From: Vsevolod Stakhov Date: Thu, 23 Apr 2009 15:42:34 +0000 (+0400) Subject: * Some more bugs are (hopefuly) fixed X-Git-Tag: 0.2.7~175 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4806dfcd8b6d6e758a9e005cbf10d8ed36d09a90;p=rspamd.git * Some more bugs are (hopefuly) fixed --- diff --git a/src/expressions.c b/src/expressions.c index cc5e09072..0ad9f1a72 100644 --- a/src/expressions.c +++ b/src/expressions.c @@ -210,6 +210,7 @@ is_regexp_flag (char a) case 's': case 'u': case 'o': + case 'r': case 'H': case 'M': case 'P': @@ -297,6 +298,8 @@ parse_expression (memory_pool_t *pool, char *line) if (line == NULL || pool == NULL) { return NULL; } + + msg_debug ("parse_expression: parsing expression {{ %s }}", line); function_stack = g_queue_new (); p = line; @@ -379,13 +382,13 @@ parse_expression (memory_pool_t *pool, char *line) case READ_REGEXP_FLAGS: if (!is_regexp_flag (*p) || *(p + 1) == '\0') { if (c != p) { - /* Copy operand */ - if (*(p + 1) == '\0' || *(p - 1) == '/') { - p++; + if (is_regexp_flag (*p) && *(p + 1) == '\0') { + p ++; } - str = memory_pool_alloc (pool, p - c + 1); - g_strlcpy (str, c - 1, (p - c + 1)); + str = memory_pool_alloc (pool, p - c + 2); + g_strlcpy (str, c - 1, (p - c + 2)); g_strstrip (str); + msg_debug ("parse_expression: found regexp: %s", str); if (strlen (str) > 0) { insert_expression (pool, &expr, EXPR_REGEXP, 0, str); } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 87d484ccf..a0d7e1f98 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -155,6 +155,7 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task) GRegex *regexp; struct uri *url; int r; + if (re == NULL) { msg_info ("process_regexp: invalid regexp passed"); @@ -162,11 +163,13 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task) } if ((r = task_cache_check (task, re)) != -1) { + msg_debug ("process_regexp: regexp /%s/ is found in cache, result: %d", re->regexp_text, r); return r == 1; } switch (re->type) { case REGEXP_NONE: + msg_warn ("process_regexp: bad error detected: /%s/ has invalid regexp type", re->regexp_text); return 0; case REGEXP_HEADER: if (re->header == NULL) { @@ -282,6 +285,8 @@ process_regexp (struct rspamd_regexp *re, struct worker_task *task) *c = t; task_cache_add (task, re, 0); return 0; + default: + msg_warn ("process_regexp: bad error detected: %p is not a valid regexp object", re); } /* Not reached */ @@ -332,6 +337,7 @@ process_regexp_expression (struct expression *expr, struct worker_task *task) GQueue *stack; gsize cur, op1, op2; struct expression *it = expr; + struct rspamd_regexp *re; gboolean try_optimize = TRUE; stack = g_queue_new (); @@ -362,11 +368,12 @@ process_regexp_expression (struct expression *expr, struct worker_task *task) it = it->next; continue; } - it->content.operand = parse_regexp (task->cfg->cfg_pool, it->content.operand, task->cfg->raw_mode); - if (it->content.operand == NULL) { + re = parse_regexp (task->cfg->cfg_pool, it->content.operand, task->cfg->raw_mode); + if (re == NULL) { msg_warn ("process_regexp_expression: cannot parse regexp, skip expression"); return FALSE; } + it->content.operand = re; it->type = EXPR_REGEXP_PARSED; /* Continue with this regexp once again */ continue;