Re: [PATCH 04/21] harden REALLOC_ARRAY and xcalloc against size_t overflow

2016-02-21 Thread Jeff King
On Sat, Feb 20, 2016 at 10:32:00PM +0100, René Scharfe wrote: > >-#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), (alloc) * sizeof(*(x))) > >+#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult((alloc), sizeof(*(x > >+#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult((alloc), >

Re: [PATCH 04/21] harden REALLOC_ARRAY and xcalloc against size_t overflow

2016-02-20 Thread René Scharfe
Am 19.02.2016 um 12:22 schrieb Jeff King: 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

[PATCH 04/21] harden REALLOC_ARRAY and xcalloc against size_t overflow

2016-02-19 Thread Jeff King
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()