vondruch / rpms / ruby

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