Check c->eidx before decrement in ecall(); close #4977

This commit is contained in:
Yukihiro "Matz" Matsumoto
2020-05-28 18:43:20 +09:00
parent ebbb4fd7fb
commit d5cca2bdb2
+4 -2
View File
@@ -336,10 +336,12 @@ ecall(mrb_state *mrb)
struct REnv *env;
ptrdiff_t cioff;
int ai = mrb_gc_arena_save(mrb);
uint16_t i = --c->eidx;
uint16_t i;
int nregs;
if (i<0) return;
if (c->eidx == 0) return;
i = --c->eidx;
/* restrict total call depth of ecall() */
if (++mrb->ecall_nest > MRB_ECALL_DEPTH_MAX) {
mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));