[前][次][番号順一覧][スレッド一覧]

ruby-changes:32946

From: nobu <ko1@a...>
Date: Mon, 17 Feb 2014 17:42:01 +0900 (JST)
Subject: [ruby-changes:32946] nobu:r45025 (trunk): marshal.c: do not recycle wrapper objects

nobu	2014-02-17 17:41:57 +0900 (Mon, 17 Feb 2014)

  New Revision: 45025

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45025

  Log:
    marshal.c: do not recycle wrapper objects
    
    * marshal.c (marshal_dump, marshal_load): do not recycle wrapper
      objects, to prevent from segfault with continuation.
      [ruby-dev:47970] [Bug #9523]

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c
    trunk/test/ruby/test_marshal.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45024)
+++ ChangeLog	(revision 45025)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Feb 17 17:41:55 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* marshal.c (marshal_dump, marshal_load): do not recycle wrapper
+	  objects, to prevent from segfault with continuation.
+	  [ruby-dev:47970] [Bug #9523]
+
 Mon Feb 17 15:43:59 2014  Zachary Scott  <e@z...>
 
 	* doc/keywords.rdoc: [DOC] Add keywords doc by documenting-ruby/ruby#29
Index: marshal.c
===================================================================
--- marshal.c	(revision 45024)
+++ marshal.c	(revision 45025)
@@ -993,8 +993,8 @@ marshal_dump(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L993
 	rb_io_write(arg->dest, arg->str);
 	rb_str_resize(arg->str, 0);
     }
-    free_dump_arg(arg);
-    rb_gc_force_recycle(wrapper); /* also guards from premature GC */
+    clear_dump_arg(arg);
+    RB_GC_GUARD(wrapper);
 
     return port;
 }
@@ -2004,8 +2004,8 @@ marshal_load(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L2004
 
     if (!NIL_P(proc)) arg->proc = proc;
     v = r_object(arg);
-    free_load_arg(arg);
-    rb_gc_force_recycle(wrapper); /* also guards from premature GC */
+    clear_load_arg(arg);
+    RB_GC_GUARD(wrapper);
 
     return v;
 }
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 45024)
+++ test/ruby/test_marshal.rb	(revision 45025)
@@ -611,4 +611,23 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L611
     end
     assert_empty(tainted.map {|x| [x, x.class]}, bug8945)
   end
+
+  class Bug9523
+    attr_reader :cc
+    def marshal_dump
+      callcc {|c| @cc = c }
+      nil
+    end
+    def marshal_load(v)
+    end
+  end
+
+  def test_continuation
+    require "continuation"
+    c = Bug9523.new
+    assert_raise_with_message(RuntimeError, /Marshal\.dump reentered at marshal_dump/) do
+      Marshal.dump(c)
+      c.cc.call
+    end
+  end
 end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]