From 3fe939564fc5f4dde52a6b9bc385e558e3423256 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 1 Feb 2013 07:35:37 +0000 Subject: marshal.c: prohibit_ivar * marshal.c (r_object0): prohibit setting instance variables of exising class/module. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_marshal.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/ruby/test_marshal.rb b/test/ruby/test_marshal.rb index 8a10ded463..4dcdb605ab 100644 --- a/test/ruby/test_marshal.rb +++ b/test/ruby/test_marshal.rb @@ -62,8 +62,8 @@ class TestMarshal < Test::Unit::TestCase def test_struct_invalid_members TestMarshal.const_set :StructInvalidMembers, Struct.new(:a) - Marshal.load("\004\bIc&TestMarshal::StructInvalidMembers\006:\020__members__\"\bfoo") assert_raise(TypeError, "[ruby-dev:31759]") { + Marshal.load("\004\bIc&TestMarshal::StructInvalidMembers\006:\020__members__\"\bfoo") TestMarshal::StructInvalidMembers.members } end @@ -538,4 +538,16 @@ class TestMarshal < Test::Unit::TestCase assert_equal(obj, loaded, bug7627) assert_nil(loaded.foo, bug7627) end + + def test_class_ivar + assert_raise(TypeError) {Marshal.load("\x04\x08Ic\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")} + assert_raise(TypeError) {Marshal.load("\x04\x08IM\x1bTestMarshal::TestClass\x06:\x0e@ivar_bug\"\x08bug")} + assert_not_operator(TestClass, :instance_variable_defined?, :@bug) + end + + def test_module_ivar + assert_raise(TypeError) {Marshal.load("\x04\x08Im\x1cTestMarshal::TestModule\x06:\x0e@ivar_bug\"\x08bug")} + assert_raise(TypeError) {Marshal.load("\x04\x08IM\x1cTestMarshal::TestModule\x06:\x0e@ivar_bug\"\x08bug")} + assert_not_operator(TestModule, :instance_variable_defined?, :@bug) + end end -- cgit v1.2.3