git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH 1/2] Fix builtin-fetch memory corruption by not overstepping array
@ 2007-09-14 22:59 Shawn O. Pearce
  2007-09-14 23:14 ` Shawn O. Pearce
  2007-09-14 23:43 ` Junio C Hamano
  0 siblings, 2 replies; 3+ messages in thread
From: Shawn O. Pearce @ 2007-09-14 22:59 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

A long time ago Junio added this line to always ensure that the
output array created by remove_duplicates() had a NULL as its
terminating node.  Today none of the downstream consumers of this
array care about a NULL terminator; they only pay attention to the
size of the array (as indicated by nr_heads).  In (nearly?) all
cases passing a NULL element will cause SIGSEGV failures.  So this
NULL terminal is not actually necessary.

Unfortunately we cannot continue to NULL terminate the array at
this point as the array may only have been allocated large enough
to match the input of nr_heads.  If there are no duplicates than
we would be trying to store NULL into heads[nr_heads] and that may
be outside of the array.

My recent series to cleanup builtin-fetch changed the allocation of
the heads array from 256 entries to exactly nr_heads thus ensuring
we were always overstepping the array and causing memory corruption.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---

 *** RESEND TO CORRECT FROM+SBO ***

 Sorry Junio.  I realized too late that the headers were wrong.
 That's what I get for not configuring ~/.gitconfig on my amd64
 Linux box.  ;-)

 builtin-fetch-pack.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index b0936cc..2977a94 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -654,7 +654,6 @@ static int remove_duplicates(int nr_heads, char **heads)
 			heads[dst] = heads[src];
 		dst++;
 	}
-	heads[dst] = 0;
 	return dst;
 }
 
-- 
1.5.3.1.921.g8c3b

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

end of thread, other threads:[~2007-09-14 23:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-14 22:59 [RESEND PATCH 1/2] Fix builtin-fetch memory corruption by not overstepping array Shawn O. Pearce
2007-09-14 23:14 ` Shawn O. Pearce
2007-09-14 23: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).