Skip to content

Commit

Permalink
lib-mail: message-address: Fix assert panic occurring in message_addr…
Browse files Browse the repository at this point in the history
…ess_parse_path() when no opening `<' is found.

Panic was:

Panic: file message-address.c: line 147 (parse_angle_addr): assertion failed: (*ctx->parser.data == '<')
  • Loading branch information
stephanbosch committed Apr 10, 2018
1 parent c4739c5 commit fbed916
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib-mail/message-address.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ message_address_parse_path_real(pool_t pool, const unsigned char *data,

if (rfc822_skip_lwsp(&ctx.parser) <= 0)
return -1;
if (*ctx.parser.data != '<')
return -1;
if ((ret=parse_angle_addr(&ctx)) < 0 ||
(ctx.addr.mailbox != NULL && ctx.addr.domain == NULL)) {
ctx.addr.invalid_syntax = TRUE;
Expand Down
28 changes: 28 additions & 0 deletions src/lib-mail/test-message-address.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,39 @@ static void test_message_address_path(void)
test_end();
}

static void test_message_address_path_invalid(void)
{
static const char *tests[] = {
">",
" > ",
"user@domain",
" user@domain ",
"user@domain>",
" user@domain> ",
"<user>",
"<@route@route2:user>",
};
const struct message_address *addr;
unsigned int i;

test_begin("message address path invalid");

for (i = 0; i < N_ELEMENTS(tests); i++) {
const char *test = tests[i];
int ret;

ret = test_parse_path(test, &addr);
test_assert_idx(ret < 0, i);
}
test_end();
}

int main(void)
{
static void (*const test_functions[])(void) = {
test_message_address,
test_message_address_path,
test_message_address_path_invalid,
NULL
};
return test_run(test_functions);
Expand Down

0 comments on commit fbed916

Please sign in to comment.