]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Properly detect end of headers position
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Jul 2016 14:04:12 +0000 (15:04 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Jul 2016 14:04:12 +0000 (15:04 +0100)
src/libmime/message.c

index b7579ba2541a6ab8c170d38117e00dfade445335..de70d76bcb2ccd18babe8714d87c16ee1c6b7e86 100644 (file)
@@ -1300,6 +1300,44 @@ rspamd_message_from_data (struct rspamd_task *task, GByteArray *data,
        }
 }
 
+static inline const gchar *
+rspamd_message_find_body_start (const gchar *headers_end, const gchar *body_end)
+{
+       const gchar *p = headers_end;
+       enum {
+               st_start = 0,
+               st_cr,
+               st_lf,
+       } state = st_start;
+
+       if (headers_end + 1 >= body_end) {
+               return headers_end;
+       }
+
+       switch (state) {
+       case st_start:
+               if (*p == '\r') {
+                       p ++;
+                       state = st_cr;
+               }
+               else if (*p == '\n') {
+                       p ++;
+                       state = st_lf;
+               }
+               break;
+       case st_cr:
+               if (*p == '\n' && p < body_end) {
+                       /* CRLF */
+                       p ++;
+               }
+               break;
+       case st_lf:
+               break;
+       }
+
+       return p;
+}
+
 gboolean
 rspamd_message_parse (struct rspamd_task *task)
 {
@@ -1415,8 +1453,12 @@ rspamd_message_parse (struct rspamd_task *task)
                        hdr_pos = rspamd_string_find_eoh (&str);
 
                        if (hdr_pos > 0 && hdr_pos < tmp->len) {
+                               static const gchar *body_start;
+
+                               body_start = rspamd_message_find_body_start (p + hdr_pos,
+                                               p + len);
                                task->raw_headers_content.begin = (gchar *) (p);
-                               task->raw_headers_content.len = (guint64) (hdr_pos);
+                               task->raw_headers_content.len = body_start - p;
 
                                if (task->raw_headers_content.len > 0) {
                                        process_raw_headers (task, task->raw_headers,