summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-class-ext
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-04-22 16:48:33 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-04-22 16:48:33 +0900
commitd3a02a297f5a2a7a7f5951168bd837e3733a3071 (patch)
tree117bb35dc1883a4954bd922b9666b8b0a673b51e /mrbgems/mruby-class-ext
parentab508e1e7f66d8e4eb6dd5f6a9cdf37c8c9e5005 (diff)
downloadmruby-d3a02a297f5a2a7a7f5951168bd837e3733a3071.tar.gz
mruby-d3a02a297f5a2a7a7f5951168bd837e3733a3071.zip
Fix `instance_exec` and `class_exec` to avoid crash on indirect calls.
Thank you @shuujii to additional report on #4973
Diffstat (limited to 'mrbgems/mruby-class-ext')
-rw-r--r--mrbgems/mruby-class-ext/src/class.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/mrbgems/mruby-class-ext/src/class.c b/mrbgems/mruby-class-ext/src/class.c
index 02ebf80cc..b7b5e18f8 100644
--- a/mrbgems/mruby-class-ext/src/class.c
+++ b/mrbgems/mruby-class-ext/src/class.c
@@ -43,10 +43,15 @@ mrb_mod_module_exec(mrb_state *mrb, mrb_value self)
const mrb_value *argv;
mrb_int argc;
mrb_value blk;
+ struct RClass *c;
mrb_get_args(mrb, "*&!", &argv, &argc, &blk);
- mrb->c->ci->target_class = mrb_class_ptr(self);
+ c = mrb_class_ptr(self);
+ if (mrb->c->ci->acc < 0) {
+ return mrb_yield_with_class(mrb, blk, argc, argv, self, c);
+ }
+ mrb->c->ci->target_class = c;
return mrb_yield_cont(mrb, blk, self, argc, argv);
}