From 57a7d70e577bd9f225085e9443964a2d43725925 Mon Sep 17 00:00:00 2001 From: Stephan Bosch <stephan@rename-it.nl> Date: Wed, 30 Dec 2015 21:38:16 +0100 Subject: [PATCH] lib-sieve: message body: Fixed assert failure occurring when text extraction is attempted on a empty or broken text part. --- src/lib-sieve/sieve-message.c | 2 +- tests/extensions/body/text.svtest | 41 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/lib-sieve/sieve-message.c b/src/lib-sieve/sieve-message.c index 9cfa4648a..bfcca53c9 100644 --- a/src/lib-sieve/sieve-message.c +++ b/src/lib-sieve/sieve-message.c @@ -974,7 +974,7 @@ static void sieve_message_part_save if ( extract_text && body_part->children == NULL && !body_part->epilogue ) { - if ( mail_html2text_content_type_match + if ( buf->used > 0 && mail_html2text_content_type_match (body_part->content_type) ) { struct mail_html2text *html2text; diff --git a/tests/extensions/body/text.svtest b/tests/extensions/body/text.svtest index c6d60e51b..2dc6a0392 100644 --- a/tests/extensions/body/text.svtest +++ b/tests/extensions/body/text.svtest @@ -182,3 +182,44 @@ test "Nested Search" { } } +/* + * Broken/Empty parts + */ + +test_set "message" text: +From: Whomever <whoever@example.com> +To: Someone <someone@example.com> +Date: Sat, 10 Oct 2009 00:30:04 +0200 +Subject: whatever +Content-Type: multipart/mixed; boundary=outer + +This is a multi-part message in MIME format. + +--outer +Content-Type: text/html + +--outer +Content-Type: text/html; charset=utf-8 +Content-Transfer-Encoding: multipart/related +Content-Disposition: inline + +<html><body>Please say Hello</body></html> + +--outer-- + +This is the end of the outer MIME multipart. +. +; + +test "Nested Search" { + if body :text :contains "Hello" { + test_fail "Cannot match empty/broken part"; + } + if body :text :contains ["<html>", "body"] { + test_fail "erroneously matched text/html markup"; + } + if body :text :contains "MIME" { + test_fail "erroneously matched multipart prologue/epilogue text"; + } +} + -- GitLab