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
Notes: sideshowbarker 2024-07-18 08:35:04 +09:00

View file

@ -411,6 +411,10 @@ static void free_impl(void* ptr)
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;
auto* ptr = malloc_impl(new_size, CallerWillInitializeMemory::Yes);
if (ptr)