Skip to content

Commit 4e80146

Browse files
jcodagnonegitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9752ad0 commit 4e80146

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

mailinfo.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,11 +1149,13 @@ void clear_mailinfo(struct mailinfo *mi)
11491149
strbuf_release(&mi->inbody_header_accum);
11501150
free(mi->message_id);
11511151

1152-
for (i = 0; mi->p_hdr_data[i]; i++)
1153-
strbuf_release(mi->p_hdr_data[i]);
1152+
if (mi->p_hdr_data)
1153+
for (i = 0; mi->p_hdr_data[i]; i++)
1154+
strbuf_release(mi->p_hdr_data[i]);
11541155
free(mi->p_hdr_data);
1155-
for (i = 0; mi->s_hdr_data[i]; i++)
1156-
strbuf_release(mi->s_hdr_data[i]);
1156+
if (mi->s_hdr_data)
1157+
for (i = 0; mi->s_hdr_data[i]; i++)
1158+
strbuf_release(mi->s_hdr_data[i]);
11571159
free(mi->s_hdr_data);
11581160

11591161
while (mi->content < mi->content_top) {

0 commit comments

Comments
 (0)