]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix Content-Type parsing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Feb 2019 15:10:52 +0000 (15:10 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 18 Feb 2019 15:10:52 +0000 (15:10 +0000)
Issue: #2757

src/libmime/mime_headers.c
src/libmime/mime_parser.c

index d0388a6323bc3c38624257cbd481a8ae29f63369..caf69cd16623f8aed770bbfe08a9ae38923ebb3c 100644 (file)
@@ -639,68 +639,69 @@ rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in,
                                if (qmarks < 3) {
                                        state = got_encoded_start;
                                }
-                               /* Finished encoded boundary */
-                               else if (rspamd_rfc2047_parser (c, p - c + 1, &encoding,
-                                               &cur_charset.begin, &cur_charset.len,
-                                               &tok_start, &tok_len)) {
-                                       /* We have a token, so we can decode it from `encoding` */
-                                       if (token->len > 0) {
-                                               if (old_charset.len == 0) {
-                                                       memcpy (&old_charset, &cur_charset,
-                                                                       sizeof (old_charset));
-                                               }
-
-                                               rspamd_mime_header_maybe_save_token (pool, out,
-                                                               token, decoded,
-                                                               &old_charset, &cur_charset);
+                               else {
+                                       /* Finished encoded boundary */
+                                       if (*c == '"') {
+                                               /* Quoted string, non-RFC conformant but used by retards */
+                                               c ++;
                                        }
+                                       if (rspamd_rfc2047_parser (c, p - c + 1, &encoding,
+                                                       &cur_charset.begin, &cur_charset.len,
+                                                       &tok_start, &tok_len)) {
+                                               /* We have a token, so we can decode it from `encoding` */
+                                               if (token->len > 0) {
+                                                       if (old_charset.len == 0) {
+                                                               memcpy (&old_charset, &cur_charset,
+                                                                               sizeof (old_charset));
+                                                       }
 
-                                       qmarks = 0;
-                                       pos = token->len;
-                                       g_byte_array_set_size (token, pos + tok_len);
+                                                       rspamd_mime_header_maybe_save_token (pool, out,
+                                                                       token, decoded,
+                                                                       &old_charset, &cur_charset);
+                                               }
 
-                                       if (encoding == RSPAMD_RFC2047_QP) {
-                                               r = rspamd_decode_qp2047_buf (tok_start, tok_len,
-                                                               token->data + pos, tok_len);
+                                               qmarks = 0;
+                                               pos = token->len;
+                                               g_byte_array_set_size (token, pos + tok_len);
 
-                                               if (r != -1) {
-                                                       token->len = pos + r;
-                                               }
-                                               else {
-                                                       /* Cannot decode qp */
-                                                       token->len -= tok_len;
-                                               }
-                                       }
-                                       else {
-                                               if (rspamd_cryptobox_base64_decode (tok_start, tok_len,
-                                                               token->data + pos, &tok_len)) {
-                                                       token->len = pos + tok_len;
-                                               }
-                                               else {
-                                                       /* Cannot decode */
-                                                       token->len -= tok_len;
-                                               }
-                                       }
+                                               if (encoding == RSPAMD_RFC2047_QP) {
+                                                       r = rspamd_decode_qp2047_buf (tok_start, tok_len,
+                                                                       token->data + pos, tok_len);
 
-                                       c = p + 1;
-                                       state = skip_spaces;
-                               }
-                               else {
-                                       /* Not encoded-word */
-                                       old_charset.len = 0;
+                                                       if (r != -1) {
+                                                               token->len = pos + r;
+                                                       } else {
+                                                               /* Cannot decode qp */
+                                                               token->len -= tok_len;
+                                                       }
+                                               } else {
+                                                       if (rspamd_cryptobox_base64_decode (tok_start, tok_len,
+                                                                       token->data + pos, &tok_len)) {
+                                                               token->len = pos + tok_len;
+                                                       } else {
+                                                               /* Cannot decode */
+                                                               token->len -= tok_len;
+                                                       }
+                                               }
 
-                                       if (token->len > 0) {
-                                               rspamd_mime_header_maybe_save_token (pool, out,
-                                                               token, decoded,
-                                                               &old_charset, &cur_charset);
-                                       }
+                                               c = p + 1;
+                                               state = skip_spaces;
+                                       } else {
+                                               /* Not encoded-word */
+                                               old_charset.len = 0;
 
-                                       g_string_append_len (out, c, p - c);
-                                       c = p;
-                                       state = parse_normal;
-                               }
+                                               if (token->len > 0) {
+                                                       rspamd_mime_header_maybe_save_token (pool, out,
+                                                                       token, decoded,
+                                                                       &old_charset, &cur_charset);
+                                               }
 
-                       }
+                                               g_string_append_len (out, c, p - c);
+                                               c = p;
+                                               state = parse_normal;
+                                       }
+                               } /* qmarks >= 3 */
+                       } /* p == '=' */
                        else {
                                state = got_encoded_start;
                        }
index 7151140cb36b3a9a0a297c3194f8c92872d48298..fb81c36ac4ff240efa83314f78b22135c1bcbc22 100644 (file)
@@ -609,7 +609,7 @@ rspamd_mime_process_multipart_node (struct rspamd_task *task,
 
                for (i = 0; i < hdrs->len; i ++) {
                        hdr = g_ptr_array_index (hdrs, i);
-                       ct = rspamd_content_type_parse (hdr->value, strlen (hdr->value),
+                       ct = rspamd_content_type_parse (hdr->decoded, strlen (hdr->decoded),
                                        task->task_pool);
 
                        /* Here we prefer multipart content-type or any content-type */
@@ -1240,7 +1240,7 @@ rspamd_mime_parse_message (struct rspamd_task *task,
        else {
                for (i = 0; i < hdrs->len; i ++) {
                        hdr = g_ptr_array_index (hdrs, i);
-                       ct = rspamd_content_type_parse (hdr->value, strlen (hdr->value),
+                       ct = rspamd_content_type_parse (hdr->decoded, strlen (hdr->decoded),
                                        task->task_pool);
 
                        /* Here we prefer multipart content-type or any content-type */