summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--struct.c2
-rw-r--r--test/ruby/test_marshal.rb8
2 files changed, 9 insertions, 1 deletions
diff --git a/struct.c b/struct.c
index 9f7277e6b2..6f67984cf2 100644
--- a/struct.c
+++ b/struct.c
@@ -48,7 +48,7 @@ struct_ivar_get(VALUE c, ID id)
for (;;) {
c = rb_class_superclass(c);
- if (c == 0 || c == rb_cStruct || c == rb_cData || c == Qnil)
+ if (c == rb_cStruct || c == rb_cData || !RTEST(c))
return Qnil;
RUBY_ASSERT(RB_TYPE_P(c, T_CLASS));
ivar = rb_attr_get(c, id);
diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb
index fc5cd9e93e..6cd0b9acc3 100644
--- a/test/ruby/test_marshal.rb
+++ b/test/ruby/test_marshal.rb
@@ -92,6 +92,14 @@ class TestMarshal < Test::Unit::TestCase
TestMarshal.instance_eval { remove_const :StructInvalidMembers }
end
+ def test_load_range_as_struct
+ assert_raise(TypeError, 'GH-6832') do
+ # Can be obtained with:
+ # $ ruby -e 'Range = Struct.new(:a, :b, :c); p Marshal.dump(Range.new(nil, nil, nil))'
+ Marshal.load("\x04\bS:\nRange\b:\x06a0:\x06b0:\x06c0")
+ end
+ end
+
class C
def initialize(str)
@str = str