diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-24 11:59:15 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-24 11:59:15 -0200 |
commit | 7e63d3da0240325db4011f5d2f2e8abfb5d60288 (patch) | |
tree | f6f486aaa9c1279ccdc26a1cc8bc814e005a277b /ldo.c | |
parent | 84e32ad2ebd6bd160c1320456743a5b1d8f233e9 (diff) | |
download | lua-7e63d3da0240325db4011f5d2f2e8abfb5d60288.tar.gz lua-7e63d3da0240325db4011f5d2f2e8abfb5d60288.tar.bz2 lua-7e63d3da0240325db4011f5d2f2e8abfb5d60288.zip |
Some bugs with stack reallocation by 'luaF_close'
(Long time without testing with '-DHARDSTACKTESTS'...)
With the introduction of to-be-closed variables, calls to 'luaF_close'
can move the stack, but some call sites where keeping pointers to the
stack without correcting them.
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -383,8 +383,10 @@ static void moveresults (lua_State *L, StkId res, int nres, int wanted) { | |||
383 | wanted = nres; /* we want all results */ | 383 | wanted = nres; /* we want all results */ |
384 | break; | 384 | break; |
385 | default: /* multiple results (or to-be-closed variables) */ | 385 | default: /* multiple results (or to-be-closed variables) */ |
386 | if (hastocloseCfunc(wanted)) { | 386 | if (hastocloseCfunc(wanted)) { /* to-be-closed variables? */ |
387 | luaF_close(L, res, LUA_OK); | 387 | ptrdiff_t savedres = savestack(L, res); |
388 | luaF_close(L, res, LUA_OK); /* may change the stack */ | ||
389 | res = restorestack(L, savedres); | ||
388 | wanted = codeNresults(wanted); /* correct value */ | 390 | wanted = codeNresults(wanted); /* correct value */ |
389 | if (wanted == LUA_MULTRET) | 391 | if (wanted == LUA_MULTRET) |
390 | wanted = nres; | 392 | wanted = nres; |
@@ -590,7 +592,8 @@ static int recover (lua_State *L, int status) { | |||
590 | if (ci == NULL) return 0; /* no recovery point */ | 592 | if (ci == NULL) return 0; /* no recovery point */ |
591 | /* "finish" luaD_pcall */ | 593 | /* "finish" luaD_pcall */ |
592 | oldtop = restorestack(L, ci->u2.funcidx); | 594 | oldtop = restorestack(L, ci->u2.funcidx); |
593 | luaF_close(L, oldtop, status); | 595 | luaF_close(L, oldtop, status); /* may change the stack */ |
596 | oldtop = restorestack(L, ci->u2.funcidx); | ||
594 | luaD_seterrorobj(L, status, oldtop); | 597 | luaD_seterrorobj(L, status, oldtop); |
595 | L->ci = ci; | 598 | L->ci = ci; |
596 | L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ | 599 | L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ |