summaryrefslogtreecommitdiffstats
path: root/src/libmime/mime_parser.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-18 12:27:00 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-03-18 12:27:00 +0000
commit5a75d743c04eb6d97023cba7daf47514b7b33b1f (patch)
treea19c96449499480528fc565074bb0022fa8e3cbf /src/libmime/mime_parser.c
parente6807e55299387221597eb8ad12f0834576c12ed (diff)
downloadrspamd-5a75d743c04eb6d97023cba7daf47514b7b33b1f.tar.gz
rspamd-5a75d743c04eb6d97023cba7daf47514b7b33b1f.zip
[Fix] Do not crash if cannot decode qp encoded part
Diffstat (limited to 'src/libmime/mime_parser.c')
-rw-r--r--src/libmime/mime_parser.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c
index a9bb0748a..98eef6d98 100644
--- a/src/libmime/mime_parser.c
+++ b/src/libmime/mime_parser.c
@@ -417,16 +417,29 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
parsed = rspamd_fstring_sized_new (part->raw_data.len);
r = rspamd_decode_qp_buf (part->raw_data.begin, part->raw_data.len,
parsed->str, parsed->allocated);
- g_assert (r != -1);
- parsed->len = r;
- part->parsed_data.begin = parsed->str;
- part->parsed_data.len = parsed->len;
- rspamd_mempool_add_destructor (task->task_pool,
- (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
+ if (r != -1) {
+ parsed->len = r;
+ part->parsed_data.begin = parsed->str;
+ part->parsed_data.len = parsed->len;
+ rspamd_mempool_add_destructor (task->task_pool,
+ (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
+ }
+ else {
+ msg_err_task ("invalid quoted-printable encoded part, assume 8bit");
+ part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
+ part->cte = RSPAMD_CTE_8BIT;
+ memcpy (parsed->str, part->raw_data.begin, part->raw_data.len);
+ parsed->len = part->raw_data.len;
+ part->parsed_data.begin = parsed->str;
+ part->parsed_data.len = parsed->len;
+ rspamd_mempool_add_destructor (task->task_pool,
+ (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed);
+ }
break;
case RSPAMD_CTE_B64:
parsed = rspamd_fstring_sized_new (part->raw_data.len / 4 * 3 + 12);
- rspamd_cryptobox_base64_decode (part->raw_data.begin, part->raw_data.len,
+ rspamd_cryptobox_base64_decode (part->raw_data.begin,
+ part->raw_data.len,
parsed->str, &parsed->len);
part->parsed_data.begin = parsed->str;
part->parsed_data.len = parsed->len;