kernel/heap: Check for multiplication overflows in calloc.

Logic inspired by musl's.
This commit is contained in:
Augustin Cavalier 2022-06-03 17:18:55 -04:00
parent eb26002b47
commit 2823fe54e1

View File

@ -2482,6 +2482,9 @@ realloc(void *address, size_t newSize)
void *
calloc(size_t numElements, size_t size)
{
if (size != 0 && numElements > (((size_t)(-1)) / size))
return NULL;
void *address = malloc(numElements * size);
if (address != NULL)
memset(address, 0, numElements * size);