mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-25 10:48:53 +00:00
LibC: Make calloc() actually fail on multiplication overflow
This commit is contained in:
parent
e4c1514033
commit
1610669519
Notes:
sideshowbarker
2024-07-18 08:35:04 +09:00
Author: https://github.com/awesomekling
Commit: 1610669519
1 changed files with 4 additions and 0 deletions
|
@ -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)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue