7585cc
From 0ade5611df9f981005eed32b369d1e699e520221 Mon Sep 17 00:00:00 2001
7585cc
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
7585cc
Date: Thu, 10 Feb 2022 13:26:44 +0100
7585cc
Subject: [PATCH] Don't query `RubyVM::FrozenCore` for class path.
7585cc
7585cc
The `RubyVM::FrozenCore` class path is corrupted during GC cycle and
7585cc
returns random garbage, which might result in segfault.
7585cc
7585cc
But since it is easy to detect the `RubyVM::FrozenCore`, just provide
7585cc
the class path explicitly as a workaround.
7585cc
7585cc
Other possibility would be to ignore `RubyVM::FrozenCore` simlarly as
7585cc
TracePoint API does:
7585cc
7585cc
https://github.com/ruby/ruby/blob/46f6575157d4c2f6bbd5693896e26a65037e5552/vm_trace.c#L411
7585cc
---
7585cc
 vm.c | 10 +++++++++-
7585cc
 1 file changed, 9 insertions(+), 1 deletion(-)
7585cc
7585cc
diff --git a/vm.c b/vm.c
7585cc
index 8ce8b279d4..3d189fa63a 100644
7585cc
--- a/vm.c
7585cc
+++ b/vm.c
7585cc
@@ -479,7 +479,15 @@ rb_dtrace_setup(rb_execution_context_t *ec, VALUE klass, ID id,
7585cc
     }
7585cc
     type = BUILTIN_TYPE(klass);
7585cc
     if (type == T_CLASS || type == T_ICLASS || type == T_MODULE) {
7585cc
-	VALUE name = rb_class_path(klass);
7585cc
+	VALUE name = Qnil;
7585cc
+	/*
7585cc
+	 * Special treatment for rb_mRubyVMFrozenCore wchi is broken by GC.
7585cc
+         * https://bugs.ruby-lang.org/issues/18257
7585cc
+	 */
7585cc
+	if (klass == rb_mRubyVMFrozenCore)
7585cc
+	    name = rb_str_new_cstr("RubyVM::FrozenCore");
7585cc
+	else
7585cc
+	    name = rb_class_path(klass);
7585cc
 	const char *classname, *filename;
7585cc
 	const char *methodname = rb_id2name(id);
7585cc
 	if (methodname && (filename = rb_source_location_cstr(&args->line_no)) != 0) {
7585cc
-- 
7585cc
2.34.1
7585cc