1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/oneway-malloc: check calloc args

This commit is contained in:
Kaspar Schleiser 2020-11-19 09:55:13 +01:00
parent 0695389dc2
commit e44fa2ba3e

View File

@ -61,6 +61,11 @@ void __attribute__((weak)) *realloc(void *ptr, size_t size)
void __attribute__((weak)) *calloc(size_t size, size_t cnt)
{
/* ensure size * cnt doesn't overflow size_t */
if (cnt && size > (size_t)-1 / cnt) {
return NULL;
}
void *mem = malloc(size * cnt);
if (mem) {
memset(mem, 0, size * cnt);