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