1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:17:44 +00:00

LibC: Make calloc() actually fail on multiplication overflow

This commit is contained in:
Andreas Kling 2021-07-21 22:37:56 +02:00
parent e4c1514033
commit 1610669519

View file

@ -411,6 +411,10 @@ static void free_impl(void* ptr)
void* calloc(size_t count, size_t size) void* calloc(size_t count, size_t size)
{ {
if (Checked<size_t>::multiplication_would_overflow(count, size)) {
errno = ENOMEM;
return nullptr;
}
size_t new_size = count * size; size_t new_size = count * size;
auto* ptr = malloc_impl(new_size, CallerWillInitializeMemory::Yes); auto* ptr = malloc_impl(new_size, CallerWillInitializeMemory::Yes);
if (ptr) if (ptr)