aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-05-25 17:41:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2022-05-25 17:41:39 -0300
commit196bb94d66e727e0aec053a0276c3ad701500762 (patch)
treea7639f32207179b5bd5e1ce04dd35972e1b2e148 /ldo.c
parent603b2c64add5fbf4b7343525cf109af0c7077695 (diff)
downloadlua-196bb94d66e727e0aec053a0276c3ad701500762.tar.gz
lua-196bb94d66e727e0aec053a0276c3ad701500762.tar.bz2
lua-196bb94d66e727e0aec053a0276c3ad701500762.zip
Bug: 'lua_settop' may use an invalid pointer to stack
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/ldo.c b/ldo.c
index 5aa6d59d..13498905 100644
--- a/ldo.c
+++ b/ldo.c
@@ -430,14 +430,15 @@ l_sinline void moveresults (lua_State *L, StkId res, int nres, int wanted) {
430 break; 430 break;
431 default: /* two/more results and/or to-be-closed variables */ 431 default: /* two/more results and/or to-be-closed variables */
432 if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ 432 if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */
433 ptrdiff_t savedres = savestack(L, res);
434 L->ci->callstatus |= CIST_CLSRET; /* in case of yields */ 433 L->ci->callstatus |= CIST_CLSRET; /* in case of yields */
435 L->ci->u2.nres = nres; 434 L->ci->u2.nres = nres;
436 luaF_close(L, res, CLOSEKTOP, 1); 435 res = luaF_close(L, res, CLOSEKTOP, 1);
437 L->ci->callstatus &= ~CIST_CLSRET; 436 L->ci->callstatus &= ~CIST_CLSRET;
438 if (L->hookmask) /* if needed, call hook after '__close's */ 437 if (L->hookmask) { /* if needed, call hook after '__close's */
438 ptrdiff_t savedres = savestack(L, res);
439 rethook(L, L->ci, nres); 439 rethook(L, L->ci, nres);
440 res = restorestack(L, savedres); /* close and hook can move stack */ 440 res = restorestack(L, savedres); /* hook can move stack */
441 }
441 wanted = decodeNresults(wanted); 442 wanted = decodeNresults(wanted);
442 if (wanted == LUA_MULTRET) 443 if (wanted == LUA_MULTRET)
443 wanted = nres; /* we want all results */ 444 wanted = nres; /* we want all results */
@@ -654,8 +655,7 @@ static int finishpcallk (lua_State *L, CallInfo *ci) {
654 else { /* error */ 655 else { /* error */
655 StkId func = restorestack(L, ci->u2.funcidx); 656 StkId func = restorestack(L, ci->u2.funcidx);
656 L->allowhook = getoah(ci->callstatus); /* restore 'allowhook' */ 657 L->allowhook = getoah(ci->callstatus); /* restore 'allowhook' */
657 luaF_close(L, func, status, 1); /* can yield or raise an error */ 658 func = luaF_close(L, func, status, 1); /* can yield or raise an error */
658 func = restorestack(L, ci->u2.funcidx); /* stack may be moved */
659 luaD_seterrorobj(L, status, func); 659 luaD_seterrorobj(L, status, func);
660 luaD_shrinkstack(L); /* restore stack size in case of overflow */ 660 luaD_shrinkstack(L); /* restore stack size in case of overflow */
661 setcistrecst(ci, LUA_OK); /* clear original status */ 661 setcistrecst(ci, LUA_OK); /* clear original status */