Skip to content

Commit

Permalink
libsel4platsupport: check num_pages after alloc
Browse files Browse the repository at this point in the history
To avoid null pointer reference

Signed-off-by: chao an <[email protected]>
  • Loading branch information
anchao authored and Indanz committed Nov 20, 2023
1 parent 30a915a commit 043999f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libsel4platsupport/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 043999f

Please sign in to comment.