From 298f383ffcc30d0799fbca0293175f647fe6bccf Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 16 Jul 2019 14:13:22 -0300 Subject: Avoid setting the stack top below upvalues to be closed When leaving a scope, the new stack top should be set only after closing any upvalue, to avoid manipulating values in an "invalid" part of the stack. --- lvm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index d365bcdd..9838500b 100644 --- a/lvm.c +++ b/lvm.c @@ -1601,15 +1601,17 @@ void luaV_execute (lua_State *L, CallInfo *ci) { int n = GETARG_B(i) - 1; /* number of results */ if (n < 0) /* not fixed? */ n = cast_int(L->top - ra); /* get what is available */ - else - L->top = ra + n; /* set call for 'luaD_poscall' */ savepc(ci); if (TESTARG_k(i)) { int nparams1 = GETARG_C(i); + if (L->top < ci->top) + L->top = ci->top; luaF_close(L, base, LUA_OK); /* there may be open upvalues */ + updatestack(ci); if (nparams1) /* vararg function? */ ci->func -= ci->u.l.nextraargs + nparams1; } + L->top = ra + n; /* set call for 'luaD_poscall' */ luaD_poscall(L, ci, n); return; } -- cgit v1.2.3-55-g6feb