Browse Source

* Allow escaped quotes in quoted strings, for example "\"some string\""

* Add warnings when we got errors while parsing rexeps
tags/0.2.7
Vsevolod Stakhov 15 years ago
parent
commit
9c455404d4
5 changed files with 36 additions and 3 deletions
  1. 1
    1
      rspamd.conf.sample
  2. 6
    0
      src/cfg_file.h
  3. 2
    2
      src/cfg_file.l
  4. 24
    0
      src/cfg_utils.c
  5. 3
    0
      src/plugins/regexp.c

+ 1
- 1
rspamd.conf.sample View 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";


+ 6
- 0
src/cfg_file.h View 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 *);

+ 2
- 2
src/cfg_file.l View 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;

%%
/*

+ 24
- 0
src/cfg_utils.c View 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

+ 3
- 0
src/plugins/regexp.c View 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) {

Loading…
Cancel
Save