From: Vsevolod Stakhov Date: Mon, 18 Feb 2019 15:10:52 +0000 (+0000) Subject: [Fix] Fix Content-Type parsing X-Git-Tag: 1.9.0~128 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9b6ae0883bfb26e2fafd3717c1e66e948917a1fc;p=rspamd.git [Fix] Fix Content-Type parsing Issue: #2757 --- diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index d0388a632..caf69cd16 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -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; } diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c index 7151140cb..fb81c36ac 100644 --- a/src/libmime/mime_parser.c +++ b/src/libmime/mime_parser.c @@ -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 */