Skip to content

Commit fac449e

Browse files
Mike Palligormunkin
authored andcommitted
snap: check J->pc is within its proto bytecode
(cherry-picked from commit 5c46f47) This commit adds an assertion to ensure that the `pc` of the snapshot being made is located within the current prototype. Violation of this assertion's condition may lead to all kinds of buggy behavior on restoration from that snapshot, depending on what is located in memory at the address under `pc`. NOTICE: This patch is only a part of the original commit, and the other part is backported in the following commit. The patch was split into two, so the test case becomes easier to implement since it can now depend on this assertion instead of memory layout. Maxim Kokryashkin: * added the description for the problem Part of tarantool/tarantool#9145
1 parent aed147c commit fac449e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/lj_snap.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ static MSize snapshot_framelinks(jit_State *J, SnapEntry *map, uint8_t *topslot)
115115
#else
116116
MSize f = 0;
117117
map[f++] = SNAP_MKPC(J->pc); /* The current PC is always the first entry. */
118+
lj_assertJ(!J->pt ||
119+
(J->pc >= proto_bc(J->pt) &&
120+
J->pc < proto_bc(J->pt) + J->pt->sizebc), "bad snapshot PC");
118121
#endif
119122
while (frame > lim) { /* Backwards traversal of all frames above base. */
120123
if (frame_islua(frame)) {

0 commit comments

Comments
 (0)