diff options
author | Jeremy Evans <[email protected]> | 2022-02-17 10:24:01 -0800 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2022-03-24 12:31:07 -0700 |
commit | 343ea9967e4a6b279eed6bd8e81ad0bdc747f254 (patch) | |
tree | 96c0a77db135ec1fdd374144e0e00238e2dfc1c3 /vm_trace.c | |
parent | 33b13bd9f19ac806c34d428af49a71c1aa286f7e (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 before attempting to create a binding for the frame.
Fixes [Bug #18487]
Co-authored-by: Alan Wu <[email protected]>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5567
Diffstat (limited to 'vm_trace.c')
-rw-r--r-- | vm_trace.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/vm_trace.c b/vm_trace.c index 5fa9acd487..b9ba6de73e 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -719,7 +719,14 @@ 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) || + VM_FRAME_RUBYFRAME_P(RUBY_VM_PREVIOUS_CONTROL_FRAME(ec->cfp)))) { + argv[4] = rb_binding_new(); + } argv[5] = klass ? klass : Qnil; rb_proc_call_with_block(proc, 6, argv, Qnil); |