cpu/esp_common: fix possible overflow in calloc implementation

This commit is contained in:
Marian Buschsieweke 2021-05-04 14:11:39 +02:00
parent 84169266b4
commit 2f08f676dc
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F

View File

@ -276,9 +276,13 @@ void* IRAM_ATTR __wrap__realloc_r(struct _reent *r, void* ptr, size_t size)
void* IRAM_ATTR __wrap__calloc_r(struct _reent *r, size_t count, size_t size)
{
void *result = heap_caps_malloc_default(count * size);
size_t size_total;
if (__builtin_mul_overflow(count, size, &size_total)) {
return NULL;
}
void *result = heap_caps_malloc_default(size_total);
if (result) {
bzero(result, count * size);
bzero(result, size_total);
}
return result;
}