From 9520455cfaae291a69a070a8d6825c9ad4f4598f Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 11 Oct 2009 12:07:45 +0200
Subject: [PATCH] Body extension: made parsing of content-type header more
 robust.

---
 src/lib-sieve/plugins/body/ext-body-common.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/lib-sieve/plugins/body/ext-body-common.c b/src/lib-sieve/plugins/body/ext-body-common.c
index 45767de5c..d3fe81452 100644
--- a/src/lib-sieve/plugins/body/ext-body-common.c
+++ b/src/lib-sieve/plugins/body/ext-body-common.c
@@ -62,8 +62,7 @@ static bool _is_wanted_content_type
 		if (wanted_subtype == NULL) {
 			/* match only main type */
 			if (strlen(*wanted_types) == type_len &&
-			    strncasecmp(*wanted_types, content_type,
-					type_len) == 0)
+			  strncasecmp(*wanted_types, content_type, type_len) == 0)
 				return TRUE;
 		} else {
 			/* match whole type/subtype */
@@ -162,12 +161,21 @@ static const char *_parse_content_type(const struct message_header_line *hdr)
 	struct rfc822_parser_context parser;
 	string_t *content_type;
 
+	/* Initialize parsing */
 	rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
 	(void)rfc822_skip_lwsp(&parser);
 
+	/* Parse content type */
 	content_type = t_str_new(64);
 	if (rfc822_parse_content_type(&parser, content_type) < 0)
 		return "";
+
+	/* Header field must end here, otherwise content-type is invalid after all */
+	(void)rfc822_skip_lwsp(&parser);
+	if ( parser.data != parser.end && *parser.data != ';' )
+		return "";
+
+	/* Success */
 	return str_c(content_type);
 }
 
-- 
GitLab