From 0f022aae0c6008fe6f2219871d32dca8b9105066 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sat, 23 Oct 2021 10:29:55 +0200 Subject: lib: increase refcount when returning cached module instance Subsequent requires of the same module returned the cached module instance without increasing the refcount, leading to use-after-free on VM tear down or garbage collection cycles. Solve this issue by properly incrementing the refcount before returning the cached module instance. Fixes: #25 Fixes: 96f140b ("lib, vm: ensure that require() compiles modules only once") Signed-off-by: Jo-Philipp Wich --- lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 0b1f663..2c91d1d 100644 --- a/lib.c +++ b/lib.c @@ -1597,7 +1597,7 @@ uc_require_path(uc_vm_t *vm, const char *path_template, const char *name, uc_val bool rv; modtable = ucv_property_get(uc_vm_scope_get(vm), "modules"); - *res = ucv_object_get(modtable, name, &rv); + *res = ucv_get(ucv_object_get(modtable, name, &rv)); if (rv) goto out; -- cgit v1.2.3