From 2b60731c0a4af9facd32e91ec2384f8132b0bf85 Mon Sep 17 00:00:00 2001 From: Axel Heider Date: Fri, 3 Nov 2023 16:15:09 +0100 Subject: [PATCH] libsel4allocman: add error check The signature allows returning an error, so this must be checked. Signed-off-by: Axel Heider --- libsel4allocman/src/bootstrap.c | 13 ++++++++++++- libsel4simple/src/simple.c | 8 +++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libsel4allocman/src/bootstrap.c b/libsel4allocman/src/bootstrap.c index f1967708b..172946b24 100644 --- a/libsel4allocman/src/bootstrap.c +++ b/libsel4allocman/src/bootstrap.c @@ -232,7 +232,14 @@ static int bootstrap_add_untypeds_from_simple(bootstrap_info_t *bs, simple_t *si if (!bs->have_boot_cspace || (bs->uts && !bs->uts_in_current_cspace)) { return 1; } - for (int i = 0; i < simple_get_untyped_count(simple); i++) { + + int cnt = simple_get_untyped_count(simple); + if (cnt < 0) { + ZF_LOGE("Could not get untyped count (%d)", cnt); + return 1; + } + + for (int i = 0; i < cnt; i++) { size_t size_bits; uintptr_t paddr; bool device; @@ -1111,6 +1118,10 @@ int allocman_add_simple_untypeds_with_regions(allocman_t *alloc, simple_t *simpl ZF_LOGF_IF(error, "bootstrap_prepare_handle_device_untyped_cap Failed"); int total_untyped = simple_get_untyped_count(simple); + if (total_untyped < 0) { + ZF_LOGW("Could not get untyped count (%d)", total_untyped); + return 0; /* don't report an error, just do nothing */ + } for(int i = 0; i < total_untyped; i++) { size_t size_bits; diff --git a/libsel4simple/src/simple.c b/libsel4simple/src/simple.c index 13c00198f..30b7e1037 100644 --- a/libsel4simple/src/simple.c +++ b/libsel4simple/src/simple.c @@ -8,7 +8,13 @@ bool simple_is_untyped_cap(simple_t *simple, seL4_CPtr pos) { - for (int i = 0; i < simple_get_untyped_count(simple); i++) { + int cnt = simple_get_untyped_count(simple); + if (cnt < 0) { + ZF_LOGE("Could not get untyped count (%d)", cnt); + return false; + } + + for (int i = 0; i < cnt; i++) { seL4_CPtr ut_pos = simple_get_nth_untyped(simple, i, NULL, NULL, NULL); if (ut_pos == pos) { return true;