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