summaryrefslogtreecommitdiffstats
path: root/src/libmime/mime_parser.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-26 15:47:14 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-12-26 15:47:14 +0000
commit0d4c60d3ca58175284d9236851c66f840cdac705 (patch)
tree55440c4d35859b44e16e5c97c62e7625ad6441ff /src/libmime/mime_parser.c
parent50a4c6d172146d1795d5b8b7ac10a0921c883576 (diff)
downloadrspamd-0d4c60d3ca58175284d9236851c66f840cdac705.tar.gz
rspamd-0d4c60d3ca58175284d9236851c66f840cdac705.zip
[Fix] Disable zero-copy mode for text parts to avoid crashes
Diffstat (limited to 'src/libmime/mime_parser.c')
-rw-r--r--src/libmime/mime_parser.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c
index 3965b9bd5..777ef074c 100644
--- a/src/libmime/mime_parser.c
+++ b/src/libmime/mime_parser.c
@@ -311,8 +311,20 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task,
case RSPAMD_CTE_7BIT:
case RSPAMD_CTE_8BIT:
case RSPAMD_CTE_UNKNOWN:
- part->parsed_data.begin = part->raw_data.begin;
- part->parsed_data.len = part->raw_data.len;
+ if (IS_CT_TEXT (part->ct)) {
+ /* Need to copy text as we have couple of in-place change functions */
+ parsed = rspamd_fstring_sized_new (part->raw_data.len);
+ parsed->len = part->raw_data.len;
+ memcpy (parsed->str, part->raw_data.begin, parsed->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);
+ }
+ else {
+ part->parsed_data.begin = part->raw_data.begin;
+ part->parsed_data.len = part->raw_data.len;
+ }
break;
case RSPAMD_CTE_QP:
parsed = rspamd_fstring_sized_new (part->raw_data.len);