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

ruby-changes:30833

From: nagachika <ko1@a...>
Date: Thu, 12 Sep 2013 01:16:28 +0900 (JST)
Subject: [ruby-changes:30833] nagachika:r42912 (ruby_2_0_0): merge revision(s) 42596, 42597, 42598, 42599: [Backport #8795]

nagachika	2013-09-12 01:16:19 +0900 (Thu, 12 Sep 2013)

  New Revision: 42912

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

  Log:
    merge revision(s) 42596,42597,42598,42599: [Backport #8795]
    
    * time.c (time_mload): ignore invalid offset and zone.
      [ruby-core:56648] [Bug #8795]
    
    * time.c (time_mload): ignore auxiliary data, offset and zone, if
      invalid.  [ruby-core:56648] [Bug #8795]
    
    * test/ruby/test_time.rb: use the in_timezone() helper
      and define it at the top with other helpers.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/test/ruby/test_time.rb
    branches/ruby_2_0_0/time.c
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/time.c
===================================================================
--- ruby_2_0_0/time.c	(revision 42911)
+++ ruby_2_0_0/time.c	(revision 42912)
@@ -849,7 +849,8 @@ static VALUE time_utc_offset _((VALUE)); https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L849
 static int obj2int(VALUE obj);
 static VALUE obj2vint(VALUE obj);
 static int month_arg(VALUE arg);
-static void validate_utc_offset(VALUE utc_offset);
+static VALUE validate_utc_offset(VALUE utc_offset);
+static VALUE validate_zone_name(VALUE zone_name);
 static void validate_vtm(struct vtm *vtm);
 static int obj2subsecx(VALUE obj, VALUE *subsecx);
 
@@ -2672,11 +2673,19 @@ month_arg(VALUE arg) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L2673
     return mon;
 }
 
-static void
+static VALUE
 validate_utc_offset(VALUE utc_offset)
 {
     if (le(utc_offset, INT2FIX(-86400)) || ge(utc_offset, INT2FIX(86400)))
 	rb_raise(rb_eArgError, "utc_offset out of range");
+    return utc_offset;
+}
+
+static VALUE
+validate_zone_name(VALUE zone_name)
+{
+    StringValueCStr(zone_name);
+    return zone_name;
 }
 
 static void
@@ -4790,8 +4799,9 @@ time_mload(VALUE time, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L4799
     get_attr(nano_num, {});
     get_attr(nano_den, {});
     get_attr(submicro, {});
-    get_attr(offset, validate_utc_offset(offset));
-    get_attr(zone, {});
+    get_attr(offset, (offset = rb_rescue(validate_utc_offset, offset, NULL, Qnil)));
+    get_attr(zone, (zone = rb_rescue(validate_zone_name, zone, NULL, Qnil)));
+
 #undef get_attr
 
     rb_copy_generic_ivar(time, str);
@@ -4877,7 +4887,7 @@ end_submicro: ; https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L4887
 	time_fixoff(time);
     }
     if (!NIL_P(zone)) {
-	tobj->vtm.zone = StringValueCStr(zone);
+	tobj->vtm.zone = RSTRING_PTR(zone);
     }
 
     return time;
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 42911)
+++ ruby_2_0_0/ChangeLog	(revision 42912)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Thu Sep 12 01:02:56 2013  Benoit Daloze  <eregontp@g...>
+
+	* test/ruby/test_time.rb: use the in_timezone() helper
+	  and define it at the top with other helpers.
+
+Thu Sep 12 01:02:56 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* time.c (time_mload): ignore auxiliary data, offset and zone, if
+	  invalid.  [ruby-core:56648] [Bug #8795]
+
 Thu Sep 12 00:22:22 2013  Kazuki Tsujimoto  <kazuki@c...>
 
 	* variable.c (classname): the name of class that has
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 42911)
+++ ruby_2_0_0/version.h	(revision 42912)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-09-12"
-#define RUBY_PATCHLEVEL 300
+#define RUBY_PATCHLEVEL 301
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 9
Index: ruby_2_0_0/test/ruby/test_time.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_time.rb	(revision 42911)
+++ ruby_2_0_0/test/ruby/test_time.rb	(revision 42912)
@@ -15,6 +15,15 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_time.rb#L15
     $VERBOSE = @verbose
   end
 
+  def in_timezone(zone)
+    orig_zone = ENV['TZ']
+
+    ENV['TZ'] = zone
+    yield
+  ensure
+    ENV['TZ'] = orig_zone
+  end
+
   def no_leap_seconds?
     # 1972-06-30T23:59:60Z is the first leap second.
     Time.utc(1972, 7, 1, 0, 0, 0) - Time.utc(1972, 6, 30, 23, 59, 59) == 1
@@ -291,18 +300,15 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_time.rb#L300
   end
 
   def test_marshal_zone
-    orig_zone = ENV['TZ']
-
     t = Time.utc(2013, 2, 24)
     assert_equal('UTC', t.zone)
     assert_equal('UTC', Marshal.load(Marshal.dump(t)).zone)
 
-    ENV['TZ'] = 'JST-9'
-    t = Time.local(2013, 2, 24)
-    assert_equal('JST', Time.local(2013, 2, 24).zone)
-    assert_equal('JST', Marshal.load(Marshal.dump(t)).zone)
-  ensure
-    ENV['TZ'] = orig_zone
+    in_timezone('JST-9') do
+      t = Time.local(2013, 2, 24)
+      assert_equal('JST', Time.local(2013, 2, 24).zone)
+      assert_equal('JST', Marshal.load(Marshal.dump(t)).zone)
+    end
   end
 
   def test_marshal_to_s
@@ -322,6 +328,34 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_time.rb#L328
     end
   end
 
+  Bug8795 = '[ruby-core:56648] [Bug #8795]'
+
+  def test_marshal_broken_offset
+    data = "\x04\bIu:\tTime\r\xEFF\x1C\x80\x00\x00\x00\x00\x06:\voffset"
+    t1 = t2 = nil
+    in_timezone('UTC') do
+      assert_nothing_raised(TypeError, ArgumentError, Bug8795) do
+        t1 = Marshal.load(data + "T")
+        t2 = Marshal.load(data + "\"\x0ebadoffset")
+      end
+      assert_equal(0, t1.utc_offset)
+      assert_equal(0, t2.utc_offset)
+    end
+  end
+
+  def test_marshal_broken_zone
+    data = "\x04\bIu:\tTime\r\xEFF\x1C\x80\x00\x00\x00\x00\x06:\tzone"
+    t1 = t2 = nil
+    in_timezone('UTC') do
+      assert_nothing_raised(TypeError, ArgumentError, Bug8795) do
+        t1 = Marshal.load(data + "T")
+        t2 = Marshal.load(data + "\"\b\0\0\0")
+      end
+      assert_equal('UTC', t1.zone)
+      assert_equal('UTC', t2.zone)
+    end
+  end
+
   def test_at3
     t2000 = get_t2000
     assert_equal(t2000, Time.at(t2000))

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r42596-42599


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

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