Skip to content
Permalink
Browse files

bugfix: LuaJIT's jit.v module might lead to segfaults due to buggy Lu…

…a stack traversal code. thanks Thibault Charbonnier for the report in #40.
  • Loading branch information...
agentzh committed Feb 19, 2019
1 parent 0e646b5 commit 864c72e31e9ea9488bd64a441790fee916481da3
Showing with 17 additions and 10 deletions.
  1. +5 −0 src/lj_debug.c
  2. +1 −0 src/lj_debug.h
  3. +11 −10 src/lj_trace.c
@@ -107,6 +107,11 @@ static BCPos debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)
return pos;
}

LJ_FUNC BCPos lj_debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe)
{
return debug_framepc(L, fn, nextframe);
}

/* -- Line numbers -------------------------------------------------------- */

/* Get line number for a bytecode position. */
@@ -26,6 +26,7 @@ typedef struct lj_Debug {
int isvararg;
} lj_Debug;

LJ_FUNC BCPos lj_debug_framepc(lua_State *L, GCfunc *fn, cTValue *nextframe);
LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size);
LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc);
LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx);
@@ -593,21 +593,22 @@ static int trace_abort(jit_State *J)
J->cur.link = 0;
J->cur.linktype = LJ_TRLINK_NONE;
lj_vmevent_send(L, TRACE,
TValue *frame;
const BCIns *pc;
cTValue *frame;
int size;
BCIns pc;
GCfunc *fn;
setstrV(L, L->top++, lj_str_newlit(L, "abort"));
setintV(L->top++, traceno);
/* Find original Lua function call to generate a better error message. */
frame = J->L->base-1;
pc = J->pc;
while (!isluafunc(frame_func(frame))) {
pc = (frame_iscont(frame) ? frame_contpc(frame) : frame_pc(frame)) - 1;
frame = frame_prev(frame);
}
/* Find original function call to generate a better error message. */
frame = lj_debug_frame(L, 0, &size);
lua_assert(frame != NULL);
fn = frame_func(frame);
if (frame == L->base-1 && isluafunc(fn))
pc = proto_bcpos(funcproto(fn), J->pc);
else
pc = lj_debug_framepc(L, fn, frame);
setfuncV(L, L->top++, fn);
setintV(L->top++, proto_bcpos(funcproto(fn), pc));
setintV(L->top++, pc);
copyTV(L, L->top++, restorestack(L, errobj));
copyTV(L, L->top++, &J->errinfo);
);

0 comments on commit 864c72e

Please sign in to comment.
You can’t perform that action at this time.