cpu/esp_common: fix possible overflow in calloc implementation
This commit is contained in:
parent
84169266b4
commit
2f08f676dc
@ -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* 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) {
|
if (result) {
|
||||||
bzero(result, count * size);
|
bzero(result, size_total);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user