multi_heap: ensure that malloc(0) return NULL pointer in any poisoning configuration

This commit is contained in:
Felipe Neves
2020-03-17 15:58:25 -03:00
committed by bot
parent 6330b3345e
commit 481379f14d
3 changed files with 24 additions and 1 deletions
+9
View File
@@ -187,6 +187,10 @@ static bool verify_fill_pattern(void *data, size_t size, bool print_errors, bool
void *multi_heap_aligned_alloc(multi_heap_handle_t heap, size_t size, size_t alignment)
{
if (!size) {
return NULL;
}
if (size > SIZE_MAX - POISON_OVERHEAD) {
return NULL;
}
@@ -213,9 +217,14 @@ void *multi_heap_aligned_alloc(multi_heap_handle_t heap, size_t size, size_t ali
void *multi_heap_malloc(multi_heap_handle_t heap, size_t size)
{
if (!size) {
return NULL;
}
if(size > SIZE_MAX - POISON_OVERHEAD) {
return NULL;
}
multi_heap_internal_lock(heap);
poison_head_t *head = multi_heap_malloc_impl(heap, size + POISON_OVERHEAD);
uint8_t *data = NULL;