mailinfo: avoid segfault when can't open files

If <msg> or <patch> files can't be opened, then mailinfo() returns an
error before it even initializes mi->p_hdr_data or mi->s_hdr_data.
When cmd_mailinfo() then calls clear_mailinfo(), we dereference the
NULL pointers trying to free their contents.

Signed-off-by: Juan F. Codagnone <jcodagnone@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Juan F. Codagnone 2018-01-24 13:56:47 -03:00 committed by Junio C Hamano
parent 9752ad0bb7
commit 4e801463c7

View File

@ -1149,11 +1149,13 @@ void clear_mailinfo(struct mailinfo *mi)
strbuf_release(&mi->inbody_header_accum);
free(mi->message_id);
for (i = 0; mi->p_hdr_data[i]; i++)
strbuf_release(mi->p_hdr_data[i]);
if (mi->p_hdr_data)
for (i = 0; mi->p_hdr_data[i]; i++)
strbuf_release(mi->p_hdr_data[i]);
free(mi->p_hdr_data);
for (i = 0; mi->s_hdr_data[i]; i++)
strbuf_release(mi->s_hdr_data[i]);
if (mi->s_hdr_data)
for (i = 0; mi->s_hdr_data[i]; i++)
strbuf_release(mi->s_hdr_data[i]);
free(mi->s_hdr_data);
while (mi->content < mi->content_top) {