check length before calling stack_copy(); based on a patch from @mirich; close #2129

parent b1b3ee45
...@@ -249,7 +249,9 @@ cipop(mrb_state *mrb) ...@@ -249,7 +249,9 @@ cipop(mrb_state *mrb)
mrb_value *p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len); mrb_value *p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len);
MRB_ENV_UNSHARE_STACK(e); MRB_ENV_UNSHARE_STACK(e);
if (len > 0) {
stack_copy(p, e->stack, len); stack_copy(p, e->stack, len);
}
e->stack = p; e->stack = p;
} }
...@@ -387,8 +389,10 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc ...@@ -387,8 +389,10 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
mrb->c->stack[0] = self; mrb->c->stack[0] = self;
if (undef) { if (undef) {
mrb->c->stack[1] = mrb_symbol_value(undef); mrb->c->stack[1] = mrb_symbol_value(undef);
if (argc > 1) {
stack_copy(mrb->c->stack+2, argv, argc-1); stack_copy(mrb->c->stack+2, argv, argc-1);
} }
}
else if (argc > 0) { else if (argc > 0) {
stack_copy(mrb->c->stack+1, argv, argc); stack_copy(mrb->c->stack+1, argv, argc);
} }
...@@ -1230,7 +1234,9 @@ RETRY_TRY_BLOCK: ...@@ -1230,7 +1234,9 @@ RETRY_TRY_BLOCK:
} }
regs[a] = mrb_ary_new_capa(mrb, m1+len+m2); regs[a] = mrb_ary_new_capa(mrb, m1+len+m2);
rest = mrb_ary_ptr(regs[a]); rest = mrb_ary_ptr(regs[a]);
if (m1 > 0) {
stack_copy(rest->ptr, stack, m1); stack_copy(rest->ptr, stack, m1);
}
if (len > 0) { if (len > 0) {
stack_copy(rest->ptr+m1, pp, len); stack_copy(rest->ptr+m1, pp, len);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment