aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorArmelle Laine <armellel@google.com>2022-10-22 06:20:40 +0000
committerArmelle Laine <armellel@google.com>2022-12-03 07:12:52 +0000
commit96f1f117f76cda66a9a0e2b2124cdfeb7295d9a3 (patch)
tree455cb42a8bc1c9142a9cd1f369ec89d9388bbb6b /lib
parentd6da9fa96c02b04f976ad5f5173a52fb17d6199b (diff)
downloadcommon-96f1f117f76cda66a9a0e2b2124cdfeb7295d9a3.tar.gz
lib: heap: prevent Illegal memory access during heap init
Bug: 252874494 Change-Id: I2a728996f0839fc869904c69e1d2b4946a8040bc
Diffstat (limited to 'lib')
-rw-r--r--lib/heap/heap_wrapper.c3
-rw-r--r--lib/heap/miniheap/miniheap.c2
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/heap/heap_wrapper.c b/lib/heap/heap_wrapper.c
index ea012191..1aa9ac37 100644
--- a/lib/heap/heap_wrapper.c
+++ b/lib/heap/heap_wrapper.c
@@ -64,6 +64,9 @@ static inline void HEAP_INIT(void)
/* start the heap off with some spare memory in the page allocator */
size_t len;
void *ptr = page_first_alloc(&len);
+ if (!ptr) {
+ panic("heap init failed");
+ }
miniheap_init(ptr, len);
}
#define HEAP_DUMP miniheap_dump
diff --git a/lib/heap/miniheap/miniheap.c b/lib/heap/miniheap/miniheap.c
index dad20f79..549afae4 100644
--- a/lib/heap/miniheap/miniheap.c
+++ b/lib/heap/miniheap/miniheap.c
@@ -172,6 +172,7 @@ try_merge:
static struct free_heap_chunk *heap_create_free_chunk(void *ptr, size_t len, bool allow_debug)
{
+ DEBUG_ASSERT(ptr);
DEBUG_ASSERT((len % sizeof(void *)) == 0); // size must be aligned on pointer boundary
#if DEBUG_HEAP
@@ -529,6 +530,7 @@ static ssize_t heap_grow(size_t size)
void miniheap_init(void *ptr, size_t len)
{
+ DEBUG_ASSERT(ptr);
LTRACEF("ptr %p, len %zu\n", ptr, len);
// create a mutex