Skip to content


Prohibit too deep mrb_funcall() recursion; ref #3421
Browse files Browse the repository at this point in the history
`mrb_funcall()` recursion can cause stack overflow easily,
so recursion depth is now limited to MRB_FUNCALL_DEPTH_MAX,
which default value is 512.
  • Loading branch information
matz committed Feb 15, 2017
1 parent 1e57fef commit 1e5b5b1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ void abort(void);
#define MRB_STACK_GROWTH 128

/* Maximum mrb_funcall() depth. Should be set lower on memory constrained systems. */

/* Maximum stack depth. Should be set lower on memory constrained systems.
The value below allows about 60000 recursive calls in the simplest case. */
Expand Down Expand Up @@ -386,6 +391,9 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
undef = mid;
if (mrb->c->ci - mrb->c->cibase > MRB_FUNCALL_DEPTH_MAX) {
mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
ci = cipush(mrb);
ci->mid = mid;
ci->proc = p;
Expand Down

0 comments on commit 1e5b5b1

Please sign in to comment.