Permalink
Browse files

Fix possible stack overflow for `method_missing`; fix #3478

Instead of shifting mruby VM stack, we always use CALL_MAXARGS.
  • Loading branch information...
matz committed Mar 2, 2017
1 parent 0bcf9e2 commit 27ec2437fd240b10d0745256e813000b3d5d359a
Showing with 5 additions and 11 deletions.
  1. +5 −11 src/vm.c
View
@@ -1188,19 +1188,13 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
mrb_method_missing(mrb, mid, recv, args);
}
mid = missing;
if (n == CALL_MAXARGS-1) {
if (n != CALL_MAXARGS) {
mrb_value blk = regs[bidx];
regs[a+1] = mrb_ary_new_from_values(mrb, n, regs+a+1);
SET_NIL_VALUE(regs[bidx]);
n++;
}
if (n == CALL_MAXARGS) {
mrb_ary_unshift(mrb, regs[a+1], sym);
}
else {
value_move(regs+a+2, regs+a+1, n+1);
regs[a+1] = sym;
n++;
regs[a+2] = blk;
n = CALL_MAXARGS;
}
mrb_ary_unshift(mrb, regs[a+1], sym);
}
/* push callinfo */

0 comments on commit 27ec243

Please sign in to comment.