From 65c4ec04dbb34dcb6c0f5bce7ee8e2f15383d399 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Tue, 29 Dec 2015 20:20:29 +0100 Subject: [PATCH] lib-sieve: message body: Fixed assert failure in handling of body parts that are converted to text. No final '\0' character was added to those body parts. This occurs for the body test with the (default) `:text' body transform. --- src/lib-sieve/sieve-message.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib-sieve/sieve-message.c b/src/lib-sieve/sieve-message.c index 8b5577329..137fc38c3 100644 --- a/src/lib-sieve/sieve-message.c +++ b/src/lib-sieve/sieve-message.c @@ -969,10 +969,8 @@ static void sieve_message_part_save char *part_data; size_t part_size; - /* Add terminating NUL to the body part buffer */ - buffer_append_c(buf, '\0'); + /* Extract text if requested */ result_buf = buf; - if ( extract_text ) { if ( mail_html2text_content_type_match (body_part->content_type) ) { @@ -984,15 +982,20 @@ static void sieve_message_part_save html2text = mail_html2text_init(0); mail_html2text_more(html2text, buf->data, buf->used, text_buf); mail_html2text_deinit(&html2text); - + result_buf = text_buf; } } + /* Add terminating NUL to the body part buffer */ + buffer_append_c(result_buf, '\0'); + + /* Make copy of the buffer */ part_data = p_malloc(pool, result_buf->used); memcpy(part_data, result_buf->data, result_buf->used); part_size = result_buf->used - 1; + /* Free text buffer if used */ if ( text_buf != NULL) buffer_free(&text_buf); -- GitLab