]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Handle empty lists in IMAP BODYSTRUCTURE parsing as invalid
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 10 Mar 2021 15:56:12 +0000 (17:56 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 16 Mar 2021 08:44:32 +0000 (08:44 +0000)
They should be NIL instead of () if they're empty.

src/lib-imap/imap-bodystructure.c
src/lib-imap/test-imap-bodystructure.c

index 34386f1d8c21eeb5b91bb21ae2a775fc4d959e8f..d00b162c54b0e8ca6d22d979e2c58ac6fd9ae568 100644 (file)
@@ -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);
index 12bd90c5f54cbe942388673b3b6600fd34cc9a8b..c0474c5db367ebd60120838e726fee8e8ea1dfac 100644 (file)
@@ -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;