From b1817b3b62280d813e86dafe27e74bfe565a372a Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 9 Jul 2021 22:11:56 +0200 Subject: vm: fix invalid memory access on GC'ing uninitialized VM context When attempting to invoke uc_vm_free() or uc_gc() on a uc_vm_t struct that has not been initialized by uc_vm_init(), the circular double linked value list is not set up, causing the GC to read invalid memory locations when attempting to traverse the object list. Back out early when the list heads are not properly set up in order to prevent this issue. Signed-off-by: Jo-Philipp Wich --- types.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types.c b/types.c index 98547e3..5808d8e 100644 --- a/types.c +++ b/types.c @@ -1763,6 +1763,10 @@ ucv_gc(uc_vm_t *vm, bool final) uc_value_t *val; size_t i; + /* back out early if value list is uninitialized */ + if (!vm->values.prev || !vm->values.next) + return; + if (!final) { /* mark reachable objects */ ucv_gc_mark(vm->globals); -- cgit v1.2.3