From b02bd63dc5cd4918230fed3344bc71e2e5540087 Mon Sep 17 00:00:00 2001 From: dearblue Date: Mon, 22 Nov 2021 21:39:39 +0900 Subject: Fixed occurs `SIGSEGV` with `mrbgems/mruby-method` Calling the `Method#{parameters,source_location}` method on a static `Proc` object resulted in `SIGSEGV`. The trigger is https://github.com/mruby/mruby/pull/5402. The original implementation of the `Method#{parameters,source_location}` method was to temporarily rewrite the object and then call the method of the same name in `Proc`. Rewriting of objects placed in the ROM section by #5402 above is prohibited by hardware such as the CPU. This caused a `SIGSEGV`. --- mrbgems/mruby-method/src/method.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'mrbgems/mruby-method') diff --git a/mrbgems/mruby-method/src/method.c b/mrbgems/mruby-method/src/method.c index 763bc5f7d..73933049f 100644 --- a/mrbgems/mruby-method/src/method.c +++ b/mrbgems/mruby-method/src/method.c @@ -9,6 +9,10 @@ mrb_noreturn void mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value args); mrb_value mrb_exec_irep(mrb_state *mrb, mrb_value self, struct RProc *p); +// Defined by mruby-proc-ext on which mruby-method depends +mrb_value mrb_proc_parameters(mrb_state *mrb, mrb_value proc); +mrb_value mrb_proc_source_location(mrb_state *mrb, struct RProc *p); + static mrb_value args_shift(mrb_state *mrb) { @@ -345,28 +349,17 @@ static mrb_value method_source_location(mrb_state *mrb, mrb_value self) { mrb_value proc = mrb_iv_get(mrb, self, MRB_SYM(_proc)); - struct RProc *rproc; - struct RClass *orig; - mrb_value ret; if (mrb_nil_p(proc)) return mrb_nil_value(); - rproc = mrb_proc_ptr(proc); - orig = rproc->c; - rproc->c = mrb->proc_class; - ret = mrb_funcall_id(mrb, proc, MRB_SYM(source_location), 0); - rproc->c = orig; - return ret; + return mrb_proc_source_location(mrb, mrb_proc_ptr(proc)); } static mrb_value method_parameters(mrb_state *mrb, mrb_value self) { mrb_value proc = mrb_iv_get(mrb, self, MRB_SYM(_proc)); - struct RProc *rproc; - struct RClass *orig; - mrb_value ret; if (mrb_nil_p(proc)) { mrb_value rest = mrb_symbol_value(MRB_SYM(rest)); @@ -374,12 +367,7 @@ method_parameters(mrb_state *mrb, mrb_value self) return mrb_ary_new_from_values(mrb, 1, &arest); } - rproc = mrb_proc_ptr(proc); - orig = rproc->c; - rproc->c = mrb->proc_class; - ret = mrb_funcall_id(mrb, proc, MRB_SYM(parameters), 0); - rproc->c = orig; - return ret; + return mrb_proc_parameters(mrb, proc); } static mrb_value -- cgit v1.2.3