Skip to content

Commit 641294c

Browse files
committed
Avoid unsafe rb_inspect call
1 parent d22290f commit 641294c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

ext/vernier/vernier.cc

-7
Original file line numberDiff line numberDiff line change
@@ -939,13 +939,6 @@ class ThreadTable {
939939
if (thread.state == Thread::State::RUNNING) {
940940
thread.pthread_id = pthread_self();
941941
thread.native_tid = get_native_thread_id();
942-
if (thread.name == "") {
943-
// rb_inspect should be safe here, as RUNNING should correspond to RESUMED hook from internal_thread_event_cb
944-
// which is called with GVL per https://github.com/ruby/ruby/blob/v3_3_0/include/ruby/thread.h#L247-L248
945-
VALUE thread_str = rb_inspect(th);
946-
if (RTEST(thread_str))
947-
thread.name = StringValueCStr(thread_str);
948-
}
949942
} else {
950943
thread.pthread_id = 0;
951944
thread.native_tid = 0;

test/test_time_collector.rb

+15
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ def test_raised_exceptions_will_output
148148
assert File.exist?(output_file)
149149
end
150150

151+
class ThreadWithInspect < ::Thread
152+
def inspect
153+
raise "boom!"
154+
end
155+
end
156+
157+
def test_thread_with_inspect
158+
result = Vernier.trace do
159+
th1 = ThreadWithInspect.new { sleep 0.01 }
160+
th1.join
161+
end
162+
163+
assert_valid_result result
164+
end
165+
151166
def assert_similar expected, actual
152167
delta_ratio =
153168
if SLOW_RUNNER

0 commit comments

Comments
 (0)