From 1883dc5bde27caec44154b7ce1f06b07f95eab3d Mon Sep 17 00:00:00 2001 From: Gary Tou Date: Tue, 25 Apr 2023 23:22:10 -0400 Subject: defined zsuper: Handle NULL superclass for `BasicObject` Prior to this commit, a segmentation fault occurred in `vm_defined`'s `zsuper` implementation after NULL is returned as `BasicObject`'s superclass. This fix returns false from `vm_defined` if the superclass is NULL. For example, the following code resulted in a segfault. ```ruby class BasicObject def seg_fault defined?(super) end end seg_fault ``` --- vm_insnhelper.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'vm_insnhelper.c') diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 917333d248..4226fdc6de 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -5051,6 +5051,8 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ if (me) { VALUE klass = vm_search_normal_superclass(me->defined_class); + if (klass == (VALUE)NULL) return false; + ID id = me->def->original_id; return rb_method_boundp(klass, id, 0); -- cgit v1.2.1