Fix cur_L restoration on error throw

When an error is thrown on the coroutine that is not the one being
currently executed, cur_L is not set up. Hence, when the running trace
exits at assertion guard right after the error is caught, Lua state is
restored from the incorrect cur_L. As a result the resulting stack is
inconsistent and the crash occurs.

This patch updates the cur_L within lj_err_throw() to the given
lua_State, where the error is raised, since this is the only coroutine
that can proceed later.
This commit is contained in:
Sergey Kaplun 2021-08-09 19:21:18 +03:00
parent 983d66b8c5
commit 90df93a45f
No known key found for this signature in database
GPG Key ID: B185BA8E3C0A10B9

View File

@ -735,6 +735,8 @@ LJ_NOINLINE void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode)
{
global_State *g = G(L);
lj_trace_abort(g);
/* Set the running lua_State as the one where the error can be handled. */
setgcref(g->cur_L, obj2gco(L));
L->status = LUA_OK;
#if LJ_UNWIND_EXT
err_raise_ext(g, errcode);