summaryrefslogtreecommitdiffhomepage
path: root/types.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-07-09 22:11:56 +0200
committerJo-Philipp Wich <jo@mein.io>2021-07-11 15:49:14 +0200
commitb1817b3b62280d813e86dafe27e74bfe565a372a (patch)
tree7806c2221cb30a54e9fb6d27a3ec939d18bb3c12 /types.c
parent498fe870251a9a73b2ed8d47d2292652bde84c3c (diff)
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 <jo@mein.io>
Diffstat (limited to 'types.c')
-rw-r--r--types.c4
1 files changed, 4 insertions, 0 deletions
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);