Skip to content

Commit

Permalink
lib-mail: parse_addr_spec: Like in rfc822_skip_comment() check if las…
Browse files Browse the repository at this point in the history
…t_comment is not NULL

This will fix possible NULL pointer dereference when caller does not set last_comment.
  • Loading branch information
pali authored and sirainen committed Jun 12, 2017
1 parent 62630b5 commit eafb1c5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lib-mail/message-address.c
Expand Up @@ -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 == '@') {
Expand All @@ -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;
}
Expand Down

0 comments on commit eafb1c5

Please sign in to comment.