use st_add and st_mult for allocation size computation
If our size computation overflows size_t, we may allocate a much smaller buffer than we expected and overflow it. It's probably impossible to trigger an overflow in most of these sites in practice, but it is easy enough convert their additions and multiplications into overflow-checking variants. This may be fixing real bugs, and it makes auditing the code easier. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
96ffc06f72
commit
50a6c8efa2
@ -47,7 +47,7 @@ static void msort_with_tmp(void *b, size_t n, size_t s,
|
||||
void git_qsort(void *b, size_t n, size_t s,
|
||||
int (*cmp)(const void *, const void *))
|
||||
{
|
||||
const size_t size = n * s;
|
||||
const size_t size = st_mult(n, s);
|
||||
char buf[1024];
|
||||
|
||||
if (size < sizeof(buf)) {
|
||||
|
Reference in New Issue
Block a user