Skip to content

Commit

Permalink
Handle mul overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian-Nordic committed Apr 4, 2022
1 parent 3b71ab9 commit ba8b7ec
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/platform/Zephyr/SysHeapMalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

extern "C" {
#include <init.h>
#include <sys/math_extras.h>
#include <sys/mutex.h>
#include <sys/sys_heap.h>
}
Expand Down Expand Up @@ -89,11 +90,18 @@ void * WRAP(malloc)(size_t size)

void * WRAP(calloc)(size_t num, size_t size)
{
void * mem = malloc(num * size);
size_t totalSize;

if (size_mul_overflow(num, size, &totalSize))
{
return nullptr;
}

void * mem = malloc(totalSize);

if (mem)
{
memset(mem, 0, num * size);
memset(mem, 0, totalSize);
}

return mem;
Expand Down

0 comments on commit ba8b7ec

Please sign in to comment.