Skip to content

Commit b563bcb

Browse files
committed
Check if OP_RETURN cross C function boundary; fix #3462
1 parent 50bbdbb commit b563bcb

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/vm.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,18 +1669,26 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
16691669
/* Fall through to OP_R_NORMAL otherwise */
16701670
if (ci->acc >=0 && proc->env && !MRB_PROC_STRICT_P(proc)) {
16711671
struct REnv *e = top_env(mrb, proc);
1672+
mrb_callinfo *ce;
16721673

16731674
if (!MRB_ENV_STACK_SHARED_P(e)) {
16741675
localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
16751676
goto L_RAISE;
16761677
}
1677-
ci = mrb->c->cibase + e->cioff;
1678-
if (ci == mrb->c->cibase) {
1678+
1679+
ce = mrb->c->cibase + e->cioff;
1680+
while (--ci > ce) {
1681+
if (ci->acc < 0) {
1682+
localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
1683+
goto L_RAISE;
1684+
}
1685+
}
1686+
if (ce == mrb->c->cibase) {
16791687
localjump_error(mrb, LOCALJUMP_ERROR_RETURN);
16801688
goto L_RAISE;
16811689
}
16821690
mrb->c->stack = mrb->c->ci->stackent;
1683-
mrb->c->ci = ci;
1691+
mrb->c->ci = ce;
16841692
break;
16851693
}
16861694
case OP_R_NORMAL:

0 commit comments

Comments
 (0)