aboutsummaryrefslogtreecommitdiffstats
path: root/vm_insnhelper.c
diff options
context:
space:
mode:
authorGary Tou <gary@garytou.com>2023-04-25 23:22:10 -0400
committerAaron Patterson <aaron.patterson@gmail.com>2023-04-26 10:21:20 -0400
commit1883dc5bde27caec44154b7ce1f06b07f95eab3d (patch)
tree561e364d5013a6a3bce15523bfbac245e933370a /vm_insnhelper.c
parentffce3117b6b615666cab8f92a7fc32ecefc0121c (diff)
downloadruby-1883dc5bde27caec44154b7ce1f06b07f95eab3d.tar.gz
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 ```
Diffstat (limited to 'vm_insnhelper.c')
-rw-r--r--vm_insnhelper.c2
1 files changed, 2 insertions, 0 deletions
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);