mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #16438 from maribu/bad_alloc
pkg/tlsf,cpu/esp_common: fix possible overflow in calloc implementations
This commit is contained in:
commit
43103a65d5
@ -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;
|
||||
}
|
||||
|
@ -71,10 +71,14 @@ ATTR_MALLOCR void *_malloc_r(struct _reent *reent_ptr, size_t bytes)
|
||||
*/
|
||||
ATTR_CALLOCR void *_calloc_r(struct _reent *reent_ptr, size_t count, size_t bytes)
|
||||
{
|
||||
void *result = _malloc_r(reent_ptr, count * bytes);
|
||||
size_t size_total;
|
||||
if (__builtin_mul_overflow(count, bytes, &size_total)) {
|
||||
return NULL;
|
||||
}
|
||||
void *result = _malloc_r(reent_ptr, size_total);
|
||||
|
||||
if (result != NULL) {
|
||||
memset(result, 0, count * bytes);
|
||||
memset(result, 0, size_total);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user