]> source.dussan.org Git - rspamd.git/commitdiff
* Allow escaped quotes in quoted strings, for example "\"some string\""
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 18 Mar 2009 17:03:36 +0000 (20:03 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Wed, 18 Mar 2009 17:03:36 +0000 (20:03 +0300)
* Add warnings when we got errors while parsing rexeps

rspamd.conf.sample
src/cfg_file.h
src/cfg_file.l
src/cfg_utils.c
src/plugins/regexp.c

index f786f744672e0845ba5d9da069f6ea27f7f6485c..7dbd744e316c8c541fc2accbb1af280d847ef397 100644 (file)
@@ -132,7 +132,7 @@ delivery {
 };
 
 
-$to_blah = "To=/blah@blah/H";
+$to_blah = "To=/\"blah@blah\"/H";
 $from_blah = "From=/blah@blah/H";
 $subject_blah = "Subject=/blah/H";
 
index cc31f7a0cfe8b8afd56f2e773c3da837001bbe8d..646f228e0c4b6e5a1cd0732f6411a43bbd1e4188 100644 (file)
@@ -312,6 +312,12 @@ struct rspamd_regexp* parse_regexp (memory_pool_t *pool, char *line);
  */
 struct expression* parse_expression (memory_pool_t *pool, char *line);
 
+/**
+ * Replace all \" with a single " in given string
+ * @param line input string
+ */
+void unescape_quotes (char *line);
+
 int yylex (void);
 int yyparse (void);
 void yyrestart (FILE *);
index 4e8e4bb8dbce567838d9cf49b261121d97f59e9a..be1e780f3e685c55effce8aceb84e5972933652b 100644 (file)
@@ -87,7 +87,7 @@ statfile_pool_size                            return STATFILE_POOL_SIZE;
 yes|YES|no|NO|[yY]|[nN]                        yylval.flag=parse_flag(yytext); return FLAG;
 \n                                                             /* ignore EOL */;
 [ \t]+                                                 /* ignore whitespace */;
-\"[^"]+\"                                              yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; return QUOTEDSTRING;
+\".+[^\\]\"                                            yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;
 \"                                                             return QUOTE;
 \$[a-zA-Z_][a-zA-Z0-9_]+               yylval.string=strdup(yytext + 1); return VARIABLE;
 [0-9]+                                                 yylval.number=strtol(yytext, NULL, 10); return NUMBER;
@@ -148,7 +148,7 @@ yes|YES|no|NO|[yY]|[nN]                     yylval.flag=parse_flag(yytext); return FLAG;
 <module>=      return EQSIGN;
 <module>[a-zA-Z0-9_%-]+        yylval.string=strdup(yytext); return PARAM;
 <module>\$[a-zA-Z_][a-zA-Z0-9_]+               yylval.string=strdup(yytext + 1); return VARIABLE;
-<module>\"[^"]+\"      yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; return QUOTEDSTRING;
+<module>\".+[^\\]\"    yylval.string=strdup(yytext + 1); yylval.string[strlen(yylval.string) - 1] = '\0'; unescape_quotes(yylval.string); return QUOTEDSTRING;
 
 %%
 /* 
index 204ed65f66dfda0ddb81a001d739e09bfdf63a69..f95237e5910e14216e573b662edd904a264a296f 100644 (file)
@@ -567,6 +567,7 @@ parse_regexp (memory_pool_t *pool, char *line)
                line ++;
        }
        if (line == '\0') {
+               msg_warn ("parse_regexp: got empty regexp");
                return NULL;
        }
        /* First try to find header name */
@@ -593,6 +594,7 @@ parse_regexp (memory_pool_t *pool, char *line)
        }
        else {
                /* We got header name earlier but have not found // expression, so it is invalid regexp */
+               msg_warn ("parse_regexp: got no header name (eg. header=) but without corresponding regexp");
                return NULL;
        }
        /* Find end */
@@ -601,6 +603,7 @@ parse_regexp (memory_pool_t *pool, char *line)
                end ++;
        }
        if (end == begin || *end != '/') {
+               msg_warn ("parse_regexp: no trailing / in regexp");
                return NULL;
        }
        /* Parse flags */
@@ -675,6 +678,11 @@ parse_regexp (memory_pool_t *pool, char *line)
        memory_pool_add_destructor (pool, (pool_destruct_func)g_regex_unref, (void *)result->regexp);
        *end = '/';
 
+       if (result->regexp == NULL || err != NULL) {
+               msg_warn ("parse_regexp: could not read regexp: %s", err->message);
+               return NULL;
+       }
+
        return result;
 }
 
@@ -712,6 +720,22 @@ parse_warn (const char *fmt, ...)
        g_warning ("%s", logbuf);
 }
 
+void
+unescape_quotes (char *line)
+{
+       char *c = line, *t;
+
+       while (*c) {
+               if (*c == '\\' && *(c + 1) == '"') {
+                       t = c;
+                       while (*t) {
+                               *t = *(t + 1);
+                               t ++;
+                       }
+               }
+               c ++;
+       }
+}
 
 /*
  * vi:ts=4
index 9ef4e1ce38ce4f43df69eca905e7f74be8c3294f..35307359dcf22e237e83f5f36bdf3b890ba1a457 100644 (file)
@@ -80,6 +80,9 @@ read_regexp_expression (memory_pool_t *pool, struct regexp_module_item *chain, c
        struct expression *e, *cur;
 
        e = parse_expression (regexp_module_ctx->regexp_pool, line);
+       if (e == NULL) {
+               msg_err ("read_regexp_extension: %s is invalid regexp extension", line);
+       }
        chain->expr = e;
        cur = e;
        while (cur) {