]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: parse_addr_spec: Like in rfc822_skip_comment() check if last_comment is...
authorPali Rohár <pali.rohar@gmail.com>
Sun, 5 Jun 2016 13:48:16 +0000 (15:48 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 6 Jun 2016 10:49:13 +0000 (13:49 +0300)
This will fix possible NULL pointer dereference when caller does not set last_comment.

src/lib-mail/message-address.c

index 9ce4a55e4885d0799fa881a9d73b5e870ec37ea8..4e861857e80c190d3a6192b97962e446e046e36f 100644 (file)
@@ -158,7 +158,8 @@ static int parse_addr_spec(struct message_address_parser_context *ctx)
        /* addr-spec       = local-part "@" domain */
        int ret, ret2;
 
-       str_truncate(ctx->parser.last_comment, 0);
+       if (ctx->parser.last_comment != NULL)
+               str_truncate(ctx->parser.last_comment, 0);
 
        ret = parse_local_part(ctx);
        if (ret != 0 && *ctx->parser.data == '@') {
@@ -167,9 +168,11 @@ static int parse_addr_spec(struct message_address_parser_context *ctx)
                        ret = ret2;
        }
 
-       if (str_len(ctx->parser.last_comment) > 0) {
-               ctx->addr.name =
-                       p_strdup(ctx->pool, str_c(ctx->parser.last_comment));
+       if (ctx->parser.last_comment != NULL) {
+               if (str_len(ctx->parser.last_comment) > 0) {
+                       ctx->addr.name =
+                               p_strdup(ctx->pool, str_c(ctx->parser.last_comment));
+               }
        }
        return ret;
 }