Blame SOURCES/dovecot-2.3.13-CVE_2020_25275regr-part2.patch

b62b43
From ec2c5ffde7a1ca63219d47831725599e7de76f7f Mon Sep 17 00:00:00 2001
b62b43
From: Timo Sirainen <timo.sirainen@open-xchange.com>
b62b43
Date: Wed, 18 Nov 2020 20:48:11 +0200
b62b43
Subject: [PATCH] lib-imap: Fix writing BODYSTRUCTURE for truncated multipart/
b62b43
 part
b62b43
b62b43
If the max nesting limit is reached, write the last part out as
b62b43
application/octet-stream. The original content-type could be confusing
b62b43
IMAP clients when they don't see any child parts.
b62b43
---
b62b43
 src/lib-imap/imap-bodystructure.c      |  6 ++++++
b62b43
 src/lib-imap/test-imap-bodystructure.c | 15 +++++++++++++++
b62b43
 2 files changed, 21 insertions(+)
b62b43
b62b43
diff --git a/src/lib-imap/imap-bodystructure.c b/src/lib-imap/imap-bodystructure.c
b62b43
index ab422c00d2..bfb6e64197 100644
b62b43
--- a/src/lib-imap/imap-bodystructure.c
b62b43
+++ b/src/lib-imap/imap-bodystructure.c
b62b43
@@ -147,6 +147,7 @@ static bool part_is_truncated(const struct message_part *part)
b62b43
 	const struct message_part_data *data = part->data;
b62b43
 
b62b43
 	i_assert((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) == 0);
b62b43
+	i_assert((part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0);
b62b43
 
b62b43
 	if (data->content_type != NULL) {
b62b43
 		if (strcasecmp(data->content_type, "message") == 0 &&
b62b43
@@ -155,6 +156,11 @@ static bool part_is_truncated(const struct message_part *part)
b62b43
 			   MESSAGE_PART_FLAG_MESSAGE_RFC822. */
b62b43
 			return TRUE;
b62b43
 		}
b62b43
+		if (strcasecmp(data->content_type, "multipart") == 0) {
b62b43
+			/* It's multipart/, but without
b62b43
+			   MESSAGE_PART_FLAG_MULTIPART. */
b62b43
+			return TRUE;
b62b43
+		}
b62b43
 	}
b62b43
 	return FALSE;
b62b43
 }
b62b43
diff --git a/src/lib-imap/test-imap-bodystructure.c b/src/lib-imap/test-imap-bodystructure.c
b62b43
index 6cb699e126..2118907e78 100644
b62b43
--- a/src/lib-imap/test-imap-bodystructure.c
b62b43
+++ b/src/lib-imap/test-imap-bodystructure.c
b62b43
@@ -556,6 +556,21 @@ static const struct {
b62b43
 		.bodystructure = "\"message\" \"rfc822\" NIL NIL NIL \"7bit\" 159 (NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL) (\"application\" \"octet-stream\" NIL NIL NIL \"7bit\" 110 NIL NIL NIL NIL) 11 NIL NIL NIL NIL",
b62b43
 		.max_depth = 2,
b62b43
 	},
b62b43
+	{
b62b43
+		.input = "Content-Type: multipart/mixed; boundary=1\n"
b62b43
+			"\n"
b62b43
+			"--1\n"
b62b43
+			"Content-Type: multipart/mixed; boundary=2\n"
b62b43
+			"\n"
b62b43
+			"--2\n"
b62b43
+			"Content-Type: multipart/mixed; boundary=3\n"
b62b43
+			"\n"
b62b43
+			"--3\n"
b62b43
+			"\n"
b62b43
+			"body\n",
b62b43
+		.bodystructure = "(\"application\" \"octet-stream\" (\"boundary\" \"2\") NIL NIL \"7bit\" 63 NIL NIL NIL NIL) \"mixed\" (\"boundary\" \"1\") NIL NIL NIL",
b62b43
+		.max_depth = 2,
b62b43
+	},
b62b43
 };
b62b43
 
b62b43
 static void test_imap_bodystructure_truncation(void)