mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-19 23:45:28 +02:00
heap: Add integer overflow checks
This commit is contained in:
@@ -47,11 +47,17 @@ void* IRAM_ATTR _realloc_r(struct _reent *r, void* ptr, size_t size)
|
||||
return heap_caps_realloc_default( ptr, size );
|
||||
}
|
||||
|
||||
void* IRAM_ATTR _calloc_r(struct _reent *r, size_t count, size_t size)
|
||||
void* IRAM_ATTR _calloc_r(struct _reent *r, size_t nmemb, size_t size)
|
||||
{
|
||||
void* result = heap_caps_malloc_default(count * size);
|
||||
if (result) {
|
||||
bzero(result, count * size);
|
||||
void *result;
|
||||
size_t size_bytes;
|
||||
if (__builtin_mul_overflow(nmemb, size, &size_bytes)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = malloc(size_bytes);
|
||||
if (result != NULL) {
|
||||
bzero(result, size_bytes);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user