From: Vsevolod Stakhov Date: Wed, 15 Jun 2016 15:49:23 +0000 (+0100) Subject: [Fix] Fix parsing of nested braces in SMTP comments X-Git-Tag: 1.3.0~331 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=64f5a8946087eca07abab3356dfc8fa339cdd6b4;p=thirdparty%2Frspamd.git [Fix] Fix parsing of nested braces in SMTP comments --- diff --git a/src/ragel/smtp_received.rl b/src/ragel/smtp_received.rl index 8e18258550..67a52e7cff 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 7161eab96a..bfd32eaaa5 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 635d47c925..3b8563e8be 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