heap: Add integer overflow checks

This commit is contained in:
Angus Gratton
2018-06-18 16:24:49 +10:00
committed by bot
parent 7933b75416
commit fd88d6d89c
5 changed files with 49 additions and 12 deletions
+10 -4
View File
@@ -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;
}