]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_address_write() - don't crash with NULL address
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 6 Mar 2018 10:14:25 +0000 (12:14 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Mar 2018 09:15:47 +0000 (11:15 +0200)
message_address_parse() can return NULL on empty address, so writing it
should produce empty address as well. Broken by
15581297511b658a29c707c6031a258bab7bf1a5

src/lib-mail/message-address.c
src/lib-mail/test-message-address.c

index d9ab110a68290534cd0a9e1b9cdd20f7a150912b..172a707d49436a90363e3ad887e65e03d04cd74a 100644 (file)
@@ -470,6 +470,9 @@ void message_address_write(string_t *str, const struct message_address *addr)
        const char *tmp;
        bool first = TRUE, in_group = FALSE;
 
+       if (addr == NULL)
+               return;
+
        /* <> path */
        if (addr->mailbox == NULL && addr->domain == NULL) {
                i_assert(addr->next == NULL);
index e0057fd9db17ce8304357f0726eab6ed50453986..c1b5566d91f2a00fdb9275e7b2e1f6d497db7dcb 100644 (file)
@@ -311,6 +311,13 @@ static void test_message_address(void)
                    cmp_addr(addr, &group_suffix));
        test_assert(strcmp(str_c(str), "group:;") == 0);
        test_end();
+
+       test_begin("message address parsing empty string");
+       test_assert(message_address_parse(unsafe_data_stack_pool, &uchar_nul, 0, 10, TRUE) == NULL);
+       str_truncate(str, 0);
+       message_address_write(str, NULL);
+       test_assert(str_len(str) == 0);
+       test_end();
 }
 
 static int