From: Timo Sirainen Date: Wed, 10 Mar 2021 15:56:12 +0000 (+0200) Subject: lib-imap: Handle empty lists in IMAP BODYSTRUCTURE parsing as invalid X-Git-Tag: 2.3.15~221 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=586cca576970cc377a40f995512dbc02981900a3;p=thirdparty%2Fdovecot%2Fcore.git lib-imap: Handle empty lists in IMAP BODYSTRUCTURE parsing as invalid They should be NIL instead of () if they're empty. --- diff --git a/src/lib-imap/imap-bodystructure.c b/src/lib-imap/imap-bodystructure.c index 34386f1d8c..d00b162c54 100644 --- a/src/lib-imap/imap-bodystructure.c +++ b/src/lib-imap/imap-bodystructure.c @@ -319,6 +319,8 @@ imap_bodystructure_params_parse(const struct imap_arg *arg, return -1; if ((list_count % 2) != 0) return -1; + if (list_count == 0) + return -1; params_count = list_count/2; params = p_new(pool, struct message_part_param, params_count+1); diff --git a/src/lib-imap/test-imap-bodystructure.c b/src/lib-imap/test-imap-bodystructure.c index 12bd90c5f5..c0474c5db3 100644 --- a/src/lib-imap/test-imap-bodystructure.c +++ b/src/lib-imap/test-imap-bodystructure.c @@ -513,8 +513,17 @@ static void test_imap_bodystructure_parse_invalid(void) { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0 NIL NIL (\"foo\" ATOM) NIL", "Invalid content-language" }, { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0 NIL NIL NIL ATOM", "Invalid content-location" }, - /* empty content-language list */ - { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0 NIL NIL ()", "Invalid content-language" }, + /* Make sure empty lists aren't allowed anywhere */ + { "foo", "\"text\" \"plain\" () NIL NIL \"7bit\" 0 0 NIL NIL NIL NIL", "Invalid content params" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") () NIL \"7bit\" 0 0 NIL NIL NIL NIL", "Invalid content-id" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL () \"7bit\" 0 0 NIL NIL NIL NIL", "Invalid content-description" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL () 0 0 NIL NIL NIL NIL", "Invalid content-transfer-encoding" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" () 0 NIL NIL NIL NIL", "Invalid size field" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 () NIL NIL NIL NIL", "Invalid lines field" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0 () NIL NIL NIL", "Invalid content-md5" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0 NIL () NIL NIL", "Invalid content-disposition" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0 NIL NIL () NIL", "Invalid content-language" }, + { "foo", "\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0 NIL NIL NIL ()", "Invalid content-location" }, }; struct message_part *parts; const char *error;