From: Vsevolod Stakhov Date: Wed, 18 Mar 2009 17:03:36 +0000 (+0300) Subject: * Allow escaped quotes in quoted strings, for example "\"some string\"" X-Git-Tag: 0.2.7~251 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c455404d443c748b6398076c1746a12a7458bfc;p=thirdparty%2Frspamd.git * Allow escaped quotes in quoted strings, for example "\"some string\"" * Add warnings when we got errors while parsing rexeps --- diff --git a/rspamd.conf.sample b/rspamd.conf.sample index f786f74467..7dbd744e31 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 cc31f7a0cf..646f228e0c 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 4e8e4bb8db..be1e780f3e 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; = return EQSIGN; [a-zA-Z0-9_%-]+ yylval.string=strdup(yytext); return PARAM; \$[a-zA-Z_][a-zA-Z0-9_]+ yylval.string=strdup(yytext + 1); return VARIABLE; -\"[^"]+\" 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; %% /* diff --git a/src/cfg_utils.c b/src/cfg_utils.c index 204ed65f66..f95237e591 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 9ef4e1ce38..35307359dc 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) {