All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mailinfo: avoid segfault when can't open files
@ 2018-01-24  2:54 Juan F. Codagnone
  2018-01-24  4:02 ` Jeff King
  0 siblings, 1 reply; 5+ messages in thread
From: Juan F. Codagnone @ 2018-01-24  2:54 UTC (permalink / raw)
  To: git; +Cc: Juan F. Codagnone

If <msg> or <patch> files can't be opened, clear_mailinfo crash as
it follows NULL pointers.

Can be reproduced using `git mailinfo . .`

Signed-off-by: Juan F. Codagnone <jcodagnone@gmail.com>
---
 mailinfo.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/mailinfo.c b/mailinfo.c
index a89db22ab..035abbbf5 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -1167,11 +1167,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 != NULL)
+		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 != NULL)
+		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) {
-- 
2.14.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-24 18:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24  2:54 [PATCH] mailinfo: avoid segfault when can't open files Juan F. Codagnone
2018-01-24  4:02 ` Jeff King
2018-01-24 16:51   ` Juan F. Codagnone
2018-01-24 18:06     ` Jeff King
2018-01-24 16:56   ` [PATCH v1] " Juan F. Codagnone

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.