[Fix] Fix parsing of nested braces in SMTP comments

This commit is contained in:
Vsevolod Stakhov 2016-06-15 16:49:23 +01:00
parent e386655418
commit 64f5a89460
3 changed files with 23 additions and 4 deletions

View File

@ -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;
}
}
}%%

View File

@ -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;
}

View File

@ -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;
}%%