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: https://github.com/SerenityOS/serenity/commit/16106695194
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)
|
||||
{
|
||||
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue