]> 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)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 08:21:27 +0000 (10:21 +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 4d4cfdadba65834e36a57f4974c81ba0895b5f96..77192d62541d993cdfc8a33fb9f87cb8407ef782 100644 (file)
@@ -430,6 +430,16 @@ 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);
+               str_append(str, "<>");
+               return;
+       }
+
        /* a) mailbox@domain
           b) name <@route:mailbox@domain>
           c) group: .. ; */
index aa0f8b46418bd0c4605a7df08c568117a915e3a0..a6f5e5e31513ba5c3c13fce216a8e1c9a1ba385c 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();
 }
 
 int main(void)