diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-15 16:49:23 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-06-15 16:49:23 +0100 |
commit | 64f5a8946087eca07abab3356dfc8fa339cdd6b4 (patch) | |
tree | a8c893e8b74e03f062cce27ad45e55dd1baa8349 /src/ragel | |
parent | e3866554181f3afc44afcd3cbd24fc2d4aac7f2d (diff) | |
download | rspamd-64f5a8946087eca07abab3356dfc8fa339cdd6b4.tar.gz rspamd-64f5a8946087eca07abab3356dfc8fa339cdd6b4.zip |
[Fix] Fix parsing of nested braces in SMTP comments
Diffstat (limited to 'src/ragel')
-rw-r--r-- | src/ragel/smtp_received.rl | 12 | ||||
-rw-r--r-- | src/ragel/smtp_received_parser.rl | 14 | ||||
-rw-r--r-- | src/ragel/smtp_whitespace.rl | 3 |
3 files changed, 24 insertions, 5 deletions
diff --git a/src/ragel/smtp_received.rl b/src/ragel/smtp_received.rl index 8e1825855..67a52e7cf 100644 --- a/src/ragel/smtp_received.rl +++ b/src/ragel/smtp_received.rl @@ -25,6 +25,11 @@ ( Domain >Reported_Domain_Start %Reported_Domain_End FWS "(" TCP_info ")" ) | # Here domain is something specified by remote side ( address_literal >Real_Domain_Start %Real_Domain_End FWS "(" TCP_info ")" ); + ccontent = ctext | FWS | '(' @{ fcall balanced_ccontent; }; + balanced_ccontent := ccontent* ')' @{ fret; }; + comment = "(" (FWS? ccontent)* FWS? ")"; + CFWS = ((FWS? comment)+ FWS?) | FWS; + From_domain = "FROM"i FWS Extended_Domain >From_Start %From_End; By_domain = CFWS "BY"i FWS Extended_Domain >By_Start %By_End; @@ -42,4 +47,11 @@ Opt_info = Via? With? ID? For? Additional_Registered_Clauses?; Received = From_domain By_domain Opt_info CFWS? ";" FWS date_time >Date_Start %Date_End CFWS?; + prepush { + if (top >= st_storage.size) { + st_storage.data = realloc (st_storage.data, (top + 1) * 2); + g_assert (st_storage.data != NULL); + stack = st_storage.data; + } + } }%% diff --git a/src/ragel/smtp_received_parser.rl b/src/ragel/smtp_received_parser.rl index 7161eab96..bfd32eaaa 100644 --- a/src/ragel/smtp_received_parser.rl +++ b/src/ragel/smtp_received_parser.rl @@ -269,8 +269,14 @@ rspamd_smtp_recieved_parse (struct rspamd_task *task, const char *data, size_t l *reported_ip_start, *reported_ip_end, *ip_start, *ip_end, *date_start; const char *p = data, *pe = data + len, *eof; - int cs, in_v6 = 0; - + int cs, in_v6 = 0, *stack = NULL; + gsize top = 0; + struct _ragel_st_storage { + int *data; + gsize size; + } st_storage; + + memset (&st_storage, 0, sizeof (st_storage)); memset (rh, 0, sizeof (*rh)); real_domain_start = NULL; real_domain_end = NULL; @@ -292,5 +298,9 @@ rspamd_smtp_recieved_parse (struct rspamd_task *task, const char *data, size_t l %% write init; %% write exec; + if (st_storage.data) { + free (st_storage.data); + } + return cs; } diff --git a/src/ragel/smtp_whitespace.rl b/src/ragel/smtp_whitespace.rl index 635d47c92..3b8563e8b 100644 --- a/src/ragel/smtp_whitespace.rl +++ b/src/ragel/smtp_whitespace.rl @@ -25,7 +25,4 @@ dot_atom_text = atext+ ("." atext+)*; #FWS = ((WSP* CRLF)? WSP+); FWS = WSP+; # We work with unfolded headers, so we can simplify machine - - comment = "(" (FWS? ctext)* FWS? ")"; - CFWS = ((FWS? comment)+ FWS?) | FWS; }%%
\ No newline at end of file |