diff options
author | Alan Wu <[email protected]> | 2020-09-01 23:13:54 -0400 |
---|---|---|
committer | Aaron Patterson <[email protected]> | 2020-09-25 09:27:49 -0700 |
commit | 24820d508bc89775e10e4e3e6e07e192540cb4a2 (patch) | |
tree | 6d61996799f1c7903164b0c67039b35054d5c87d /ext/objspace/objspace.c | |
parent | 3a00f2a0f4325cbeea96fe3b6fbc774e8a172920 (diff) |
Return nil when argument to ObjectSpace.internal_class_of is T_IMEMO
The added test case crashes the interpreter because it makes
ObjectSpace.internal_class_of return the second VALUE slot of an AST
imemo object. The second VALUE slot of `struct rb_ast_struct` is
not a VALUE and not a pointer to a Ruby object.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3503
Diffstat (limited to 'ext/objspace/objspace.c')
-rw-r--r-- | ext/objspace/objspace.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c index 262640d30c..3bfb79dc1f 100644 --- a/ext/objspace/objspace.c +++ b/ext/objspace/objspace.c @@ -895,8 +895,13 @@ objspace_internal_class_of(VALUE self, VALUE obj) obj = (VALUE)DATA_PTR(obj); } - klass = CLASS_OF(obj); - return wrap_klass_iow(klass); + if (RB_TYPE_P(obj, T_IMEMO)) { + return Qnil; + } + else { + klass = CLASS_OF(obj); + return wrap_klass_iow(klass); + } } /* |