]> git.ipfire.org Git - thirdparty/git.git/commit - wrapper.c
harden REALLOC_ARRAY and xcalloc against size_t overflow
authorJeff King <peff@peff.net>
Mon, 22 Feb 2016 22:43:18 +0000 (17:43 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Feb 2016 22:50:32 +0000 (14:50 -0800)
commite7792a74bcf7fcd554b4546fc91122b8c2af7d75
treef20e2c07219368119a058fc93a6b632abbe0dc54
parent5b442c4f2723211ce0d862571e88ee206bfd51bf
harden REALLOC_ARRAY and xcalloc against size_t overflow

REALLOC_ARRAY inherently involves a multiplication which can
overflow size_t, resulting in a much smaller buffer than we
think we've allocated. We can easily harden it by using
st_mult() to check for overflow.  Likewise, we can add
ALLOC_ARRAY to do the same thing for xmalloc calls.

xcalloc() should already be fine, because it takes the two
factors separately, assuming the system calloc actually
checks for overflow. However, before we even hit the system
calloc(), we do our memory_limit_check, which involves a
multiplication. Let's check for overflow ourselves so that
this limit cannot be bypassed.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h
wrapper.c