git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] get_sha1_oneline: do not leak or double free
@ 2010-12-13  3:01 Nguyễn Thái Ngọc Duy
  2010-12-13  3:01 ` [PATCH 2/3] get_sha1_oneline: let callers initialize the commit tips for traverse Nguyễn Thái Ngọc Duy
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-12-13  3:01 UTC (permalink / raw)
  To: git, Junio C Hamano, Jonathan Niedier
  Cc: Kevin Ballard, Yann Dirson, Jeff King, Jakub Narebski,
	Thiago Farina, Nguyễn Thái Ngọc Duy

Double free can happen when commit->buffer == NULL in the first
iteration, then != NULL in the next two iterations.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 sha1_name.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 2c3a5fb..13ee6f5 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -718,13 +718,13 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 		commit = pop_most_recent_commit(&list, ONELINE_SEEN);
 		if (!parse_object(commit->object.sha1))
 			continue;
-		free(temp_commit_buffer);
 		if (commit->buffer)
 			p = commit->buffer;
 		else {
 			p = read_sha1_file(commit->object.sha1, &type, &size);
 			if (!p)
 				continue;
+			free(temp_commit_buffer);
 			temp_commit_buffer = p;
 		}
 		if (!(p = strstr(p, "\n\n")))
@@ -740,6 +740,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 	free_commit_list(list);
 	for (l = backup; l; l = l->next)
 		clear_commit_marks(l->item, ONELINE_SEEN);
+	free_commit_list(backup);
 	return retval;
 }
 
-- 
1.7.3.3.476.g10a82

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

end of thread, other threads:[~2010-12-16  0:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-13  3:01 [PATCH 1/3] get_sha1_oneline: do not leak or double free Nguyễn Thái Ngọc Duy
2010-12-13  3:01 ` [PATCH 2/3] get_sha1_oneline: let callers initialize the commit tips for traverse Nguyễn Thái Ngọc Duy
2010-12-13  3:01 ` [PATCH 3/3] get_sha1: support ref^{/regex} syntax Nguyễn Thái Ngọc Duy
2010-12-13  3:10   ` Nguyen Thai Ngoc Duy
2010-12-13  4:40     ` Jonathan Nieder
2010-12-15  0:50   ` Junio C Hamano
2010-12-15  1:58     ` Nguyen Thai Ngoc Duy
2010-12-15  2:56       ` Junio C Hamano
2010-12-15  3:12         ` Nguyen Thai Ngoc Duy
2010-12-15  9:02           ` [PATCH] get_sha1: handle special case $commit^{/} Nguyễn Thái Ngọc Duy
2010-12-15 23:44             ` Junio C Hamano
2010-12-16  0:23               ` Nguyen Thai Ngoc Duy
2010-12-13  6:12 ` [PATCH 1/3] get_sha1_oneline: do not leak or double free Junio C Hamano
2010-12-13  6:19   ` Junio C Hamano
2010-12-13  6:27     ` Nguyen Thai Ngoc Duy
2010-12-13  6:31     ` Junio C Hamano
2010-12-13  6:43       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).