From 043999f481d8f72f7993eb3d27f3cf3eb66b00a7 Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 11 Sep 2023 16:43:20 +0800 Subject: [PATCH] libsel4platsupport: check num_pages after alloc To avoid null pointer reference Signed-off-by: chao an --- libsel4platsupport/src/io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libsel4platsupport/src/io.c b/libsel4platsupport/src/io.c index 59031d3e1..5b10f1939 100644 --- a/libsel4platsupport/src/io.c +++ b/libsel4platsupport/src/io.c @@ -140,10 +140,10 @@ static void *sel4platsupport_map_paddr_with_page_size(sel4platsupport_io_mapper_ uintptr_t offset = paddr - start; size += offset; - io_mapping_t *mapping = new_node(BYTES_TO_SIZE_BITS_PAGES(size, page_size_bits)); - assert(mapping->num_pages << page_size_bits >= size); + size_t num_pages = BYTES_TO_SIZE_BITS_PAGES(size, page_size_bits); + io_mapping_t *mapping = new_node(num_pages); if (!mapping) { - ZF_LOGE("Failed to allocate node for %zu pages", mapping->num_pages); + ZF_LOGE("Failed to allocate node for %zu pages", num_pages); return NULL; } mapping->page_size_bits = page_size_bits;