Skip to content

Commit

Permalink
marshal.c: undumpable hidden objects
Browse files Browse the repository at this point in the history
* marshal.c (w_object): internal objects are not dumpable.
  [ruby-core:61677] [Bug ruby#9674]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 26, 2014
1 parent 1dd5270 commit 3935f2a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Wed Mar 26 11:20:24 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
Wed Mar 26 11:20:50 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>

* 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]
Expand Down
5 changes: 5 additions & 0 deletions marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 7 additions & 0 deletions test/thread/test_cv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,18 @@ def test_dup
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
7 changes: 7 additions & 0 deletions test/thread/test_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ def test_dup
end
end

(DumpableQueue = Queue.dup).class_eval {remove_method :marshal_dump}

def test_dump
bug9674 = '[ruby-core:61677] [Bug #9674]'
q = Queue.new
Expand All @@ -227,5 +229,10 @@ def test_dump
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

0 comments on commit 3935f2a

Please sign in to comment.