Skip to content

Commit

Permalink
lib-mail: message_address_write() - don't crash with NULL address
Browse files Browse the repository at this point in the history
message_address_parse() can return NULL on empty address, so writing it
should produce empty address as well. Broken by
1558129
  • Loading branch information
sirainen authored and villesavolainen committed Mar 12, 2018
1 parent d9846c9 commit 9f2fe27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib-mail/message-address.c
Expand Up @@ -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: .. ; */
Expand Down
7 changes: 7 additions & 0 deletions src/lib-mail/test-message-address.c
Expand Up @@ -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)
Expand Down

0 comments on commit 9f2fe27

Please sign in to comment.