Bug: 'lua_settop' may use an invalid pointer to stack

This commit is contained in:
Roberto Ierusalimschy
2022-05-25 17:41:39 -03:00
parent 603b2c64ad
commit 196bb94d66
5 changed files with 34 additions and 12 deletions

5
lapi.c
View File

@@ -197,7 +197,7 @@ LUA_API void lua_settop (lua_State *L, int idx) {
newtop = L->top + diff;
if (diff < 0 && L->tbclist >= newtop) {
lua_assert(hastocloseCfunc(ci->nresults));
luaF_close(L, newtop, CLOSEKTOP, 0);
newtop = luaF_close(L, newtop, CLOSEKTOP, 0);
}
L->top = newtop; /* correct top only after closing any upvalue */
lua_unlock(L);
@@ -210,8 +210,7 @@ LUA_API void lua_closeslot (lua_State *L, int idx) {
level = index2stack(L, idx);
api_check(L, hastocloseCfunc(L->ci->nresults) && L->tbclist == level,
"no variable to close at given level");
luaF_close(L, level, CLOSEKTOP, 0);
level = index2stack(L, idx); /* stack may be moved */
level = luaF_close(L, level, CLOSEKTOP, 0);
setnilvalue(s2v(level));
lua_unlock(L);
}