]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix parsing of nested braces in SMTP comments
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Jun 2016 15:49:23 +0000 (16:49 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Jun 2016 15:49:23 +0000 (16:49 +0100)
src/ragel/smtp_received.rl
src/ragel/smtp_received_parser.rl
src/ragel/smtp_whitespace.rl

index 8e182585504ce0c8d5f9ffd2b2b9659ac9bc6ca9..67a52e7cffcfd47c097dafc489e71d075ddc6a57 100644 (file)
                   ( 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;
 
   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;
+    }
+  }
 }%%
index 7161eab96a59ed74839775db8fb57da58f06ea1d..bfd32eaaa576073c5f1868b149d02122a1011b8d 100644 (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;
 }
index 635d47c9257b6ac59f0f194b6a1bc605f3d25d50..3b8563e8be03e7ffd77f11bcb87f4018920b8392 100644 (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;
 }%%
\ No newline at end of file