summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorviralpraxis <[email protected]>2024-11-30 00:13:54 +0300
committerPeter Zhu <[email protected]>2024-11-29 18:42:48 -0500
commit660b995365f719fa59ed6f2809bb1527e6470d14 (patch)
tree059b45d0d13c59c7750cead45b3d12c32273b825
parent88764dde78ee3475cd61447e45945a6569e8d639 (diff)
[Bug #20915] Fix SEGV with `TracePoint#parameters` and aliased C method
The following snippet results with a SEGV: ```ruby C = Class.new do alias_method :new_to_s, :to_s end TracePoint.new(:c_call, &:parameters).enable { C.new.new_to_s } ``` at MRI 3.3.6 and ruby 3.4.0dev The root cause of the issue lies in the `rb_tracearg_parameters` function within the `RUBY_EVENT_C_RETURN` branch. Specifically, when the invoked method is an alias for a C function, `rb_method_entry_without_refinements(..., trace_arg->called_id, ...)` may return NULL. In that case we can fallback to `trace_arg->id`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12186
-rw-r--r--test/ruby/test_settracefunc.rb16
-rw-r--r--vm_trace.c3
2 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 472d66fbba..37358757a6 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -94,6 +94,22 @@ class TestSetTraceFunc < Test::Unit::TestCase
assert_equal([[:req]], parameters)
end
+ def test_c_call_aliased_method
+ # [Bug #20915]
+ klass = Class.new do
+ alias_method :new_method, :method
+ end
+
+ instance = klass.new
+ parameters = nil
+
+ TracePoint.new(:c_call) do |tp|
+ parameters = tp.parameters
+ end.enable { instance.new_method(:to_s) }
+
+ assert_equal([[:req]], parameters)
+ end
+
def test_call
events = []
name = "#{self.class}\##{__method__}"
diff --git a/vm_trace.c b/vm_trace.c
index f7baf3b309..99e853f1b0 100644
--- a/vm_trace.c
+++ b/vm_trace.c
@@ -937,6 +937,9 @@ rb_tracearg_parameters(rb_trace_arg_t *trace_arg)
const rb_method_entry_t *me;
VALUE iclass = Qnil;
me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->called_id, &iclass);
+ if (!me) {
+ me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->id, &iclass);
+ }
return rb_unnamed_parameters(rb_method_entry_arity(me));
}
break;