Permalink
Browse files

Prohibit too deep `mrb_funcall()` recursion; ref #3421

`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 1e5b5b14d7468ca4fedaa9ba1c9dba0ff67d7ea8
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/vm.c
View
@@ -40,6 +40,11 @@ void abort(void);
#define MRB_STACK_GROWTH 128
#endif
/* Maximum mrb_funcall() depth. Should be set lower on memory constrained systems. */
#ifndef MRB_FUNCALL_DEPTH_MAX
#define MRB_FUNCALL_DEPTH_MAX 512
#endif
/* Maximum stack depth. Should be set lower on memory constrained systems.
The value below allows about 60000 recursive calls in the simplest case. */
#ifndef MRB_STACK_MAX
@@ -386,6 +391,9 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
undef = mid;
argc++;
}
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;

0 comments on commit 1e5b5b1

Please sign in to comment.