aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-17 11:01:05 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-17 11:01:05 -0300
commita2195644d89812e5b157ce7bac35543e06db05e3 (patch)
tree878e4e64731fc598e8868b37888b7da4aa447dbb /ldo.c
parent1ecfbfa1a1debd2258decdf7c1954ac6f9761699 (diff)
downloadlua-a2195644d89812e5b157ce7bac35543e06db05e3.tar.gz
lua-a2195644d89812e5b157ce7bac35543e06db05e3.tar.bz2
lua-a2195644d89812e5b157ce7bac35543e06db05e3.zip
Fixed bug: invalid 'oldpc' when returning to a function
The field 'L->oldpc' is not always updated when control returns to a function; an invalid value can seg. fault when computing 'changedline'. (One example is an error in a finalizer; control can return to 'luaV_execute' without executing 'luaD_poscall'.) Instead of trying to fix all possible corner cases, it seems safer to be resilient to invalid values for 'oldpc'. Valid but wrong values at most cause an extra call to a line hook.
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/ldo.c b/ldo.c
index 4c976a14..98dd9fbb 100644
--- a/ldo.c
+++ b/ldo.c
@@ -327,7 +327,7 @@ static StkId rethook (lua_State *L, CallInfo *ci, StkId firstres, int nres) {
327 ptrdiff_t oldtop = savestack(L, L->top); /* hook may change top */ 327 ptrdiff_t oldtop = savestack(L, L->top); /* hook may change top */
328 int delta = 0; 328 int delta = 0;
329 if (isLuacode(ci)) { 329 if (isLuacode(ci)) {
330 Proto *p = clLvalue(s2v(ci->func))->p; 330 Proto *p = ci_func(ci)->p;
331 if (p->is_vararg) 331 if (p->is_vararg)
332 delta = ci->u.l.nextraargs + p->numparams + 1; 332 delta = ci->u.l.nextraargs + p->numparams + 1;
333 if (L->top < ci->top) 333 if (L->top < ci->top)
@@ -340,8 +340,8 @@ static StkId rethook (lua_State *L, CallInfo *ci, StkId firstres, int nres) {
340 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */ 340 luaD_hook(L, LUA_HOOKRET, -1, ftransfer, nres); /* call it */
341 ci->func -= delta; 341 ci->func -= delta;
342 } 342 }
343 if (isLua(ci->previous)) 343 if (isLua(ci = ci->previous))
344 L->oldpc = ci->previous->u.l.savedpc; /* update 'oldpc' */ 344 L->oldpc = pcRel(ci->u.l.savedpc, ci_func(ci)->p); /* update 'oldpc' */
345 return restorestack(L, oldtop); 345 return restorestack(L, oldtop);
346} 346}
347 347