diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-18 20:03:36 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-18 20:03:36 +0300 |
commit | 9c455404d443c748b6398076c1746a12a7458bfc (patch) | |
tree | 1f6174f446b4257291ef723b4f43ad9f06b7931d | |
parent | 8cc22288806b9ff7115cb8f30349029714e2d89a (diff) | |
download | rspamd-9c455404d443c748b6398076c1746a12a7458bfc.tar.gz rspamd-9c455404d443c748b6398076c1746a12a7458bfc.zip |
* Allow escaped quotes in quoted strings, for example "\"some string\""
* Add warnings when we got errors while parsing rexeps
-rw-r--r-- | rspamd.conf.sample | 2 | ||||
-rw-r--r-- | src/cfg_file.h | 6 | ||||
-rw-r--r-- | src/cfg_file.l | 4 | ||||
-rw-r--r-- | src/cfg_utils.c | 24 | ||||
-rw-r--r-- | src/plugins/regexp.c | 3 |
5 files changed, 36 insertions, 3 deletions
diff --git a/rspamd.conf.sample b/rspamd.conf.sample index f786f7446..7dbd744e3 100644 --- a/rspamd.conf.sample +++ b/rspamd.conf.sample @@ -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"; diff --git a/src/cfg_file.h b/src/cfg_file.h index cc31f7a0c..646f228e0 100644 --- a/src/cfg_file.h +++ b/src/cfg_file.h @@ -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 *); diff --git a/src/cfg_file.l b/src/cfg_file.l index 4e8e4bb8d..be1e780f3 100644 --- a/src/cfg_file.l +++ b/src/cfg_file.l @@ -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; %% /* diff --git a/src/cfg_utils.c b/src/cfg_utils.c index 204ed65f6..f95237e59 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -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 diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 9ef4e1ce3..35307359d 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -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) { |