diff options
author | Juan F. Codagnone <jcodagnone@gmail.com> | 2018-01-24 17:56:47 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-01-24 19:52:26 +0100 |
commit | 4e801463c7d2b26de747d3684cf75b722b0594af (patch) | |
tree | 2704f8dfc3229d531420a854fd43098a8e8d01f0 /mailinfo.c | |
parent | Git 2.12.5 (diff) | |
download | git-4e801463c7d2b26de747d3684cf75b722b0594af.tar.xz git-4e801463c7d2b26de747d3684cf75b722b0594af.zip |
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>
Diffstat (limited to 'mailinfo.c')
-rw-r--r-- | mailinfo.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/mailinfo.c b/mailinfo.c index a489d9d0fb..36ec927b9e 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -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) { |