heap: Fix erroneous value returned by heap_caps_get_allocated_size() when poisoning is enabled

When light (or comprehensive) poisoning is enabled, the size requested by the user for allocation
is extended by a few bytes to store the canary header and footer. heap_caps_get_allocated_size() should
return the original size asked by the user (without the additional canary bytes).

test_malloc.c extended with a new test assuring that  heap_caps_get_allocated_size() returns the proper size
regardless of the degree of poisoning.
This commit is contained in:
Guillaume Souchere
2023-01-31 09:41:56 +01:00
parent 1195b6cb2b
commit ba1d7f8d1c
2 changed files with 24 additions and 2 deletions

View File

@@ -383,6 +383,7 @@ size_t multi_heap_get_allocated_size(multi_heap_handle_t heap, void *p)
poison_head_t *head = verify_allocated_region(p, true);
assert(head != NULL);
size_t result = multi_heap_get_allocated_size_impl(heap, head);
subtract_poison_overhead(&result);
return result;
}