Skip to content

Commit 745fe4c

Browse files
committed
merge revision(s) 660b995: [Backport #20915]
[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`.
1 parent 1e48631 commit 745fe4c

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

test/ruby/test_settracefunc.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ def test_c_call_removed_method
9393
assert_equal([[:req]], parameters)
9494
end
9595

96+
def test_c_call_aliased_method
97+
# [Bug #20915]
98+
klass = Class.new do
99+
alias_method :new_method, :method
100+
end
101+
102+
instance = klass.new
103+
parameters = nil
104+
105+
TracePoint.new(:c_call) do |tp|
106+
parameters = tp.parameters
107+
end.enable { instance.new_method(:to_s) }
108+
109+
assert_equal([[:req]], parameters)
110+
end
111+
96112
def test_call
97113
events = []
98114
name = "#{self.class}\##{__method__}"

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 6
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 114
14+
#define RUBY_PATCHLEVEL 115
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

vm_trace.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,9 @@ rb_tracearg_parameters(rb_trace_arg_t *trace_arg)
937937
const rb_method_entry_t *me;
938938
VALUE iclass = Qnil;
939939
me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->called_id, &iclass);
940+
if (!me) {
941+
me = rb_method_entry_without_refinements(trace_arg->klass, trace_arg->id, &iclass);
942+
}
940943
return rb_unnamed_parameters(rb_method_entry_arity(me));
941944
}
942945
break;

0 commit comments

Comments
 (0)