summaryrefslogtreecommitdiffhomepage
path: root/vm.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-07-08 12:29:36 +0200
committerJo-Philipp Wich <jo@mein.io>2021-07-11 15:49:14 +0200
commit0f69f099dba58e23e6438023619c002cd82eacf2 (patch)
treed6c9f40566043c0d2fc21f519322bab4ad6cda11 /vm.c
parent6bcc318de336e1cb3264fb306c8ce132b8703ebc (diff)
vm: fix invalid memory access on toplevel function calls
When a function is invoked directly, e.g. through uc_vm_invoke(), the call stack is empty, so avoid accessing the first call frame unless we actually need to, which is only the case if the function is invoked with spread args which can only happen with calls from manged code. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/vm.c b/vm.c
index 9997580..a5c4b8c 100644
--- a/vm.c
+++ b/vm.c
@@ -447,7 +447,7 @@ static bool
uc_vm_call_function(uc_vm *vm, uc_value_t *ctx, uc_value_t *fno, bool mcall, size_t argspec)
{
size_t i, j, stackoff, nargs = argspec & 0xffff, nspreads = argspec >> 16;
- uc_callframe *frame = uc_vm_current_frame(vm);
+ uc_callframe *frame = NULL;
uc_value_t *ellip, *arg;
uc_function_t *function;
uc_closure_t *closure;
@@ -465,6 +465,8 @@ uc_vm_call_function(uc_vm *vm, uc_value_t *ctx, uc_value_t *fno, bool mcall, siz
/* argument list contains spread operations, we need to reshuffle the stack */
if (nspreads > 0) {
+ frame = uc_vm_current_frame(vm);
+
/* create temporary array */
ellip = ucv_array_new_length(vm, nargs);