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

ruby-changes:40895

From: nagachika <ko1@a...>
Date: Wed, 9 Dec 2015 01:45:07 +0900 (JST)
Subject: [ruby-changes:40895] nagachika:r52974 (ruby_2_2): merge revision(s) 52856, 52906: [Backport #11760]

nagachika	2015-12-09 01:44:45 +0900 (Wed, 09 Dec 2015)

  New Revision: 52974

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

  Log:
    merge revision(s) 52856,52906: [Backport #11760]
    
    * encoding.c (enc_m_loader): defer finding encoding object not to
      be infected by marshal source.  [ruby-core:71793] [Bug #11760]
    
    * marshal.c (r_object0): enable compatible loader on USERDEF
      class.  the loader function is called with the class itself,
      instead of an allocated object, and the loaded data.
    
    * marshal.c (compat_allocator_table): intialize
      compat_allocator_tbl on demand.
    
    * object.c (rb_undefined_alloc): extract from rb_obj_alloc.
    
    * marshal.c (compat_allocator_table): initialize

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/encoding.c
    branches/ruby_2_2/internal.h
    branches/ruby_2_2/marshal.c
    branches/ruby_2_2/object.c
    branches/ruby_2_2/test/ruby/test_encoding.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/encoding.c
===================================================================
--- ruby_2_2/encoding.c	(revision 52973)
+++ ruby_2_2/encoding.c	(revision 52974)
@@ -1216,6 +1216,14 @@ enc_compatible_p(VALUE klass, VALUE str1 https://github.com/ruby/ruby/blob/trunk/ruby_2_2/encoding.c#L1216
 
 /* :nodoc: */
 static VALUE
+enc_s_alloc(VALUE klass)
+{
+    rb_undefined_alloc(klass);
+    return Qnil;
+}
+
+/* :nodoc: */
+static VALUE
 enc_dump(int argc, VALUE *argv, VALUE self)
 {
     rb_scan_args(argc, argv, "01", 0);
@@ -1226,6 +1234,13 @@ enc_dump(int argc, VALUE *argv, VALUE se https://github.com/ruby/ruby/blob/trunk/ruby_2_2/encoding.c#L1234
 static VALUE
 enc_load(VALUE klass, VALUE str)
 {
+    return str;
+}
+
+/* :nodoc: */
+static VALUE
+enc_m_loader(VALUE klass, VALUE str)
+{
     return enc_find(klass, str);
 }
 
@@ -1879,7 +1894,7 @@ Init_Encoding(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/encoding.c#L1894
     int i;
 
     rb_cEncoding = rb_define_class("Encoding", rb_cObject);
-    rb_undef_alloc_func(rb_cEncoding);
+    rb_define_alloc_func(rb_cEncoding, enc_s_alloc);
     rb_undef_method(CLASS_OF(rb_cEncoding), "new");
     rb_define_method(rb_cEncoding, "to_s", enc_name, 0);
     rb_define_method(rb_cEncoding, "inspect", enc_inspect, 0);
@@ -1911,6 +1926,8 @@ Init_Encoding(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/encoding.c#L1926
     for (i = 0; i < enc_table.count; ++i) {
 	rb_ary_push(list, enc_new(enc_table.list[i].enc));
     }
+
+    rb_marshal_define_compat(rb_cEncoding, Qnil, NULL, enc_m_loader);
 }
 
 /* locale insensitive ctype functions */
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 52973)
+++ ruby_2_2/ChangeLog	(revision 52974)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Wed Dec  9 01:28:54 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* encoding.c (enc_m_loader): defer finding encoding object not to
+	  be infected by marshal source.  [ruby-core:71793] [Bug #11760]
+
+	* marshal.c (r_object0): enable compatible loader on USERDEF
+	  class.  the loader function is called with the class itself,
+	  instead of an allocated object, and the loaded data.
+
+	* marshal.c (compat_allocator_table): initialize
+	  compat_allocator_tbl on demand.
+
+	* object.c (rb_undefined_alloc): extract from rb_obj_alloc.
+
 Wed Dec  9 01:24:57 2015  Rei Odaira  <Rei.Odaira@g...>
 
 	* ext/-test-/file/fs.c: need to include sys/statvfs.h
Index: ruby_2_2/object.c
===================================================================
--- ruby_2_2/object.c	(revision 52973)
+++ ruby_2_2/object.c	(revision 52974)
@@ -1771,6 +1771,13 @@ rb_class_initialize(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/ruby_2_2/object.c#L1771
     return klass;
 }
 
+void
+rb_undefined_alloc(VALUE klass)
+{
+    rb_raise(rb_eTypeError, "allocator undefined for %"PRIsVALUE,
+	     klass);
+}
+
 /*
  *  call-seq:
  *     class.allocate()   ->   obj
@@ -1807,8 +1814,7 @@ rb_obj_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/object.c#L1814
     }
     allocator = rb_get_alloc_func(klass);
     if (!allocator) {
-	rb_raise(rb_eTypeError, "allocator undefined for %"PRIsVALUE,
-		 klass);
+	rb_undefined_alloc(klass);
     }
 
 #if !defined(DTRACE_PROBES_DISABLED) || !DTRACE_PROBES_DISABLED
Index: ruby_2_2/internal.h
===================================================================
--- ruby_2_2/internal.h	(revision 52973)
+++ ruby_2_2/internal.h	(revision 52974)
@@ -851,6 +851,7 @@ rb_float_new_inline(double d) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/internal.h#L851
 void rb_obj_copy_ivar(VALUE dest, VALUE obj);
 VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
 VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
+NORETURN(void rb_undefined_alloc(VALUE klass));
 
 struct RBasicRaw {
     VALUE flags;
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 52973)
+++ ruby_2_2/version.h	(revision 52974)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.4"
 #define RUBY_RELEASE_DATE "2015-12-09"
-#define RUBY_PATCHLEVEL 221
+#define RUBY_PATCHLEVEL 222
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 12
Index: ruby_2_2/marshal.c
===================================================================
--- ruby_2_2/marshal.c	(revision 52973)
+++ ruby_2_2/marshal.c	(revision 52974)
@@ -124,6 +124,8 @@ mark_marshal_compat_t(void *tbl) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L124
     st_foreach(tbl, mark_marshal_compat_i, 0);
 }
 
+static st_table *compat_allocator_table(void);
+
 void
 rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE))
 {
@@ -142,7 +144,7 @@ rb_marshal_define_compat(VALUE newclass, https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L144
     compat->dumper = dumper;
     compat->loader = loader;
 
-    st_insert(compat_allocator_tbl, (st_data_t)allocator, (st_data_t)compat);
+    st_insert(compat_allocator_table(), (st_data_t)allocator, (st_data_t)compat);
 }
 
 #define MARSHAL_INFECTION FL_TAINT
@@ -1820,6 +1822,7 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1822
         {
 	    VALUE klass = path2class(r_unique(arg));
 	    VALUE data;
+	    st_data_t d;
 
 	    if (!rb_obj_respond_to(klass, s_load, TRUE)) {
 		rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
@@ -1833,7 +1836,11 @@ r_object0(struct load_arg *arg, int *ivp https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L1836
 	    v = rb_funcall2(klass, s_load, 1, &data);
 	    check_load_arg(arg, s_load);
 	    v = r_entry(v, arg);
-            v = r_leave(v, arg);
+	    if (st_lookup(compat_allocator_tbl, (st_data_t)rb_get_alloc_func(klass), &d)) {
+		marshal_compat_t *compat = (marshal_compat_t*)d;
+		v = compat->loader(klass, v);
+	    }
+	    v = r_post_proc(v, arg);
 	}
         break;
 
@@ -2198,13 +2205,19 @@ Init_marshal(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/marshal.c#L2205
     rb_define_const(rb_mMarshal, "MAJOR_VERSION", INT2FIX(MARSHAL_MAJOR));
     /* minor version */
     rb_define_const(rb_mMarshal, "MINOR_VERSION", INT2FIX(MARSHAL_MINOR));
+}
 
+static st_table *
+compat_allocator_table(void)
+{
+    if (compat_allocator_tbl) return compat_allocator_tbl;
     compat_allocator_tbl = st_init_numtable();
 #undef RUBY_UNTYPED_DATA_WARNING
 #define RUBY_UNTYPED_DATA_WARNING 0
     compat_allocator_tbl_wrapper =
 	Data_Wrap_Struct(rb_cData, mark_marshal_compat_t, 0, compat_allocator_tbl);
     rb_gc_register_mark_object(compat_allocator_tbl_wrapper);
+    return compat_allocator_tbl;
 }
 
 VALUE
Index: ruby_2_2/test/ruby/test_encoding.rb
===================================================================
--- ruby_2_2/test/ruby/test_encoding.rb	(revision 52973)
+++ ruby_2_2/test/ruby/test_encoding.rb	(revision 52974)
@@ -33,6 +33,9 @@ class TestEncoding < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_encoding.rb#L33
       assert_raise(TypeError) { e.dup }
       assert_raise(TypeError) { e.clone }
       assert_equal(e.object_id, Marshal.load(Marshal.dump(e)).object_id)
+      assert_not_predicate(e, :tainted?)
+      Marshal.load(Marshal.dump(e).taint)
+      assert_not_predicate(e, :tainted?, '[ruby-core:71793] [Bug #11760]')
     end
   end
 

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r52856,52906


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

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