diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-04-06 19:14:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-06 19:14:03 -0700 |
commit | 0b091fdac6ceb33b7379ceddc9a49a79d0e158b2 (patch) | |
tree | 3ec9799bb7c38ce87b24380f8008ed07467f48e5 /vm_trace.c | |
parent | bff12e1a9a726baef8d5d8876669a1506555ec09 (diff) |
Raise RuntimeError if Kernel#binding is called from a non-Ruby frame
Check whether the current or previous frame is a Ruby frame in
call_trace_func and rb_tracearg_binding before attempting to
create a binding for the frame.
Fixes [Bug #18487]
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5767
Merged-By: jeremyevans <code@jeremyevans.net>
Diffstat (limited to 'vm_trace.c')
-rw-r--r-- | vm_trace.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/vm_trace.c b/vm_trace.c index 653e9a510a..99d3104b40 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -721,7 +721,13 @@ call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas argv[1] = filename; argv[2] = INT2FIX(line); argv[3] = id ? ID2SYM(id) : Qnil; - argv[4] = (self && (filename != Qnil)) ? rb_binding_new() : Qnil; + argv[4] = Qnil; + if (self && (filename != Qnil) && + event != RUBY_EVENT_C_CALL && + event != RUBY_EVENT_C_RETURN && + (VM_FRAME_RUBYFRAME_P(ec->cfp) && imemo_type_p((VALUE)ec->cfp->iseq, imemo_iseq))) { + argv[4] = rb_binding_new(); + } argv[5] = klass ? klass : Qnil; rb_proc_call_with_block(proc, 6, argv, Qnil); @@ -952,7 +958,7 @@ rb_tracearg_binding(rb_trace_arg_t *trace_arg) rb_control_frame_t *cfp; cfp = rb_vm_get_binding_creatable_next_cfp(trace_arg->ec, trace_arg->cfp); - if (cfp) { + if (cfp && imemo_type_p((VALUE)cfp->iseq, imemo_iseq)) { return rb_vm_make_binding(trace_arg->ec, cfp); } else { |