summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-10-31 22:42:52 +0100
committerJo-Philipp Wich <jo@mein.io>2020-10-31 22:42:52 +0100
commit67d7d0f263c1c20fa1e29b755f4f74cda64d4a42 (patch)
tree8b472f6f524b5d3f05c5e0597395b9f7ca37aa3f
parentbe3a61d576581278177a4fcc4c436f99611ed057 (diff)
lib: fix potential null pointer deref on not found cmdline module
When a module is requested via -m but not found on the system, we do not have a context opcode available when instantiating the exception, which leads to a segmentation faul when attempting to access the source text offset. Avoid the deref by checking the opcode pointer for non-null. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lib.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib.c b/lib.c
index 809fef0..eb9ef60 100644
--- a/lib.c
+++ b/lib.c
@@ -1716,7 +1716,8 @@ ut_require(struct ut_state *s, uint32_t off, struct json_object *args)
search = sc ? json_object_object_get(sc->scope, "REQUIRE_SEARCH_PATH") : NULL;
if (!json_object_is_type(search, json_type_array))
- return ut_new_exception(s, op->off, "Global require search path not set");
+ return ut_new_exception(s, op ? op->off : 0,
+ "Global require search path not set");
for (arridx = 0, arrlen = json_object_array_length(search); arridx < arrlen; arridx++) {
se = json_object_array_get_idx(search, arridx);
@@ -1730,7 +1731,8 @@ ut_require(struct ut_state *s, uint32_t off, struct json_object *args)
return res;
}
- return ut_new_exception(s, op->off, "No module named '%s' could be found", name);
+ return ut_new_exception(s, op ? op->off : 0,
+ "No module named '%s' could be found", name);
}
static struct json_object *