From 3935f2ae6e315e4e163e9891fe5d50ae606827ac Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 26 Mar 2014 02:20:52 +0000 Subject: marshal.c: undumpable hidden objects * marshal.c (w_object): internal objects are not dumpable. [ruby-core:61677] [Bug #9674] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- marshal.c | 5 +++++ test/thread/test_cv.rb | 7 +++++++ test/thread/test_queue.rb | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f1a2545394..2fc19c9e21 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Wed Mar 26 11:20:24 2014 Nobuyoshi Nakada +Wed Mar 26 11:20:50 2014 Nobuyoshi Nakada + + * marshal.c (w_object): internal objects are not dumpable. + [ruby-core:61677] [Bug #9674] * ext/thread/thread.c (undumpable): ConditionVariable and Queue are not dumpable. [ruby-core:61677] [Bug #9674] diff --git a/marshal.c b/marshal.c index 7772b4cb2a..e8791d90c7 100644 --- a/marshal.c +++ b/marshal.c @@ -677,6 +677,11 @@ w_object(VALUE obj, struct dump_arg *arg, int limit) else { VALUE v; + if (!RBASIC_CLASS(obj)) { + rb_raise(rb_eTypeError, "can't dump internal %s", + rb_builtin_type_name(BUILTIN_TYPE(obj))); + } + arg->infection |= (int)FL_TEST(obj, MARSHAL_INFECTION); if (rb_obj_respond_to(obj, s_mdump, TRUE)) { diff --git a/test/thread/test_cv.rb b/test/thread/test_cv.rb index bb0bcb8685..9f9e08e2ec 100644 --- a/test/thread/test_cv.rb +++ b/test/thread/test_cv.rb @@ -197,11 +197,18 @@ INPUT end end + (DumpableCV = ConditionVariable.dup).class_eval {remove_method :marshal_dump} + def test_dump bug9674 = '[ruby-core:61677] [Bug #9674]' condvar = ConditionVariable.new assert_raise_with_message(TypeError, /#{ConditionVariable}/, bug9674) do Marshal.dump(condvar) end + + condvar = DumpableCV.new + assert_raise_with_message(TypeError, /internal Array/, bug9674) do + Marshal.dump(condvar) + end end end diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb index b3662742c1..cda76ce61c 100644 --- a/test/thread/test_queue.rb +++ b/test/thread/test_queue.rb @@ -216,6 +216,8 @@ class TestQueue < Test::Unit::TestCase end end + (DumpableQueue = Queue.dup).class_eval {remove_method :marshal_dump} + def test_dump bug9674 = '[ruby-core:61677] [Bug #9674]' q = Queue.new @@ -227,5 +229,10 @@ class TestQueue < Test::Unit::TestCase assert_raise_with_message(TypeError, /#{SizedQueue}/, bug9674) do Marshal.dump(sq) end + + q = DumpableQueue.new + assert_raise_with_message(TypeError, /internal Array/, bug9674) do + Marshal.dump(q) + end end end -- cgit v1.2.3