heap: Add integer overflow checks on MALLOC_CAP_32BIT & MALLOC_CAP_EXEC

This commit is contained in:
Angus Gratton
2019-03-11 10:49:51 +11:00
committed by bot
parent 5beb2802e0
commit 2dd3344342
6 changed files with 42 additions and 20 deletions

View File

@@ -109,13 +109,18 @@ void* test_calloc_wrapper(size_t count, size_t size)
TEST_CASE("alloc overflows should all fail", "[heap]")
{
/* allocates 8 bytes */
/* allocates 8 bytes if size_t overflows */
TEST_ASSERT_NULL(test_calloc_wrapper(SIZE_MAX / 2 + 4, 2));
/* will overflow if any poisoning is enabled
(should fail for sensible OOM reasons, otherwise) */
TEST_ASSERT_NULL(test_malloc_wrapper(SIZE_MAX - 1));
TEST_ASSERT_NULL(test_calloc_wrapper(SIZE_MAX - 1, 1));
/* will overflow when the size is rounded up to word align it */
TEST_ASSERT_NULL(heap_caps_malloc(SIZE_MAX-1, MALLOC_CAP_32BIT));
TEST_ASSERT_NULL(heap_caps_malloc(SIZE_MAX-1, MALLOC_CAP_EXEC));
}
TEST_CASE("unreasonable allocs should all fail", "[heap]")