OSDN Git Service

Fix builtin-fetch memory corruption by not overstepping array
authorShawn O. Pearce <spearce@spearce.org>
Fri, 14 Sep 2007 22:59:53 +0000 (18:59 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 Sep 2007 10:22:31 +0000 (03:22 -0700)
commite8a37b89f7c4fd4a10104a1c4d6021a707f70613
tree142c4aaa6e54a49b31318d87efa92682649443da
parente4022ed2c85825f238661e3e532b0bb108b5e318
Fix builtin-fetch memory corruption by not overstepping array

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-fetch-pack.c