From 024a6071cac749504e0b26a915bda4f52c41a892 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 18 Jul 2019 11:26:03 -0300 Subject: Small bug with stack reallocation OP_RETURN must update trap before updating stack. (Bug detected with -DHARDSTACKTESTS). Also, in 'luaF_close', do not create a variable with 'uplevel(uv)', as the stack may change and invalidate this value. (This is not a bug, but could become one if 'upl' was used again.) --- lvm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index 7e6f148d..c1b6749d 100644 --- a/lvm.c +++ b/lvm.c @@ -1574,8 +1574,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { savepc(ci); /* some calls here can raise errors */ if (TESTARG_k(i)) { /* close upvalues from current call; the compiler ensures - that there are no to-be-closed variables here */ + that there are no to-be-closed variables here, so this + call cannot change the stack */ luaF_close(L, base, NOCLOSINGMETH); + lua_assert(base == ci->func + 1); } if (!ttisfunction(s2v(ra))) { /* not a function? */ luaD_tryfuncTM(L, ra); /* try '__call' metamethod */ @@ -1602,10 +1604,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { if (n < 0) /* not fixed? */ n = cast_int(L->top - ra); /* get what is available */ savepc(ci); - if (TESTARG_k(i)) { + if (TESTARG_k(i)) { /* may there be open upvalues? */ if (L->top < ci->top) L->top = ci->top; - luaF_close(L, base, LUA_OK); /* there may be open upvalues */ + luaF_close(L, base, LUA_OK); + updatetrap(ci); updatestack(ci); } if (nparams1) /* vararg function? */ -- cgit v1.2.3-55-g6feb