]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-address: Fix assert panic occurring in message_address_parse_path...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 10 Apr 2018 00:36:44 +0000 (02:36 +0200)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Tue, 10 Apr 2018 00:59:22 +0000 (02:59 +0200)
Panic was:

Panic: file message-address.c: line 147 (parse_angle_addr): assertion failed: (*ctx->parser.data == '<')

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

index 172a707d49436a90363e3ad887e65e03d04cd74a..f7cc27f48ef1b1fb3988b52ac354996ca371b97a 100644 (file)
@@ -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;
index c1b5566d91f2a00fdb9275e7b2e1f6d497db7dcb..21084deec99eae038ada398d0050cf2762e62eed 100644 (file)
@@ -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);