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

ruby-changes:32812

From: nobu <ko1@a...>
Date: Sun, 9 Feb 2014 02:13:59 +0900 (JST)
Subject: [ruby-changes:32812] nobu:r44891 (trunk): marshal.c: Numerics are not tainted

nobu	2014-02-09 02:13:55 +0900 (Sun, 09 Feb 2014)

  New Revision: 44891

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

  Log:
    marshal.c: Numerics are not tainted
    
    * include/ruby/ruby.h (OBJ_TAINTABLE, OBJ_TAINT, OBJ_INFECT),
      marshal.c (r_entry0): all Numerics never be tainted now.
      [ruby-core:57346] [Bug #8945]

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/ruby.h
    trunk/marshal.c
    trunk/test/ruby/test_marshal.rb
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 44890)
+++ include/ruby/ruby.h	(revision 44891)
@@ -1175,14 +1175,14 @@ struct RBignum { https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1175
 #define FL_UNSET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags &= ~(f);} while (0)
 #define FL_REVERSE(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags ^= (f);} while (0)
 
+#define OBJ_TAINTABLE(x) (FL_ABLE(x) && BUILTIN_TYPE(x) != T_BIGNUM && BUILTIN_TYPE(x) != T_FLOAT)
 #define OBJ_TAINTED(x) (!!FL_TEST((x), FL_TAINT))
-#define OBJ_TAINT(x) FL_SET((x), FL_TAINT)
+#define OBJ_TAINT(x) (OBJ_TAINTABLE(x) ? (RBASIC(x)->flags |= FL_TAINT) : 0)
 #define OBJ_UNTRUSTED(x) OBJ_TAINTED(x)
 #define OBJ_UNTRUST(x) OBJ_TAINT(x)
-#define OBJ_INFECT(x,s) do { \
-  if (FL_ABLE(x) && FL_ABLE(s)) \
-    RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT; \
-} while (0)
+#define OBJ_INFECT(x,s) ( \
+    (OBJ_TAINTABLE(x) && FL_ABLE(s)) ? \
+    RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT : 0)
 
 #define OBJ_FROZEN(x) (!!(FL_ABLE(x)?(RBASIC(x)->flags&(FL_FREEZE)):(FIXNUM_P(x)||FLONUM_P(x)||SYMBOL_P(x))))
 #define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44890)
+++ ChangeLog	(revision 44891)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Feb  9 02:13:53 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* include/ruby/ruby.h (OBJ_TAINTABLE, OBJ_TAINT, OBJ_INFECT),
+	  marshal.c (r_entry0): all Numerics never be tainted now.
+	  [ruby-core:57346] [Bug #8945]
+
 Sat Feb  8 23:40:35 2014  Vit Ondruch  <vondruch@r...>
 
 	* configure.in: add qouting brackets and append wildcard for the
Index: marshal.c
===================================================================
--- marshal.c	(revision 44890)
+++ marshal.c	(revision 44891)
@@ -1356,9 +1356,9 @@ r_entry0(VALUE v, st_index_t num, struct https://github.com/ruby/ruby/blob/trunk/marshal.c#L1356
     }
     if (arg->infection &&
 	!RB_TYPE_P(v, T_CLASS) && !RB_TYPE_P(v, T_MODULE)) {
-	FL_SET(v, arg->infection);
+	OBJ_TAINT(v);
 	if ((VALUE)real_obj != Qundef)
-	    FL_SET((VALUE)real_obj, arg->infection);
+	    OBJ_TAINT((VALUE)real_obj);
     }
     return v;
 }
Index: test/ruby/test_marshal.rb
===================================================================
--- test/ruby/test_marshal.rb	(revision 44890)
+++ test/ruby/test_marshal.rb	(revision 44891)
@@ -601,4 +601,14 @@ class TestMarshal < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_marshal.rb#L601
     bare = "".force_encoding(Encoding::ASCII_8BIT) << packed
     assert_equal(Marshal.dump(bare), Marshal.dump(packed))
   end
+
+  def test_untainted_numeric
+    bug8945 = '[ruby-core:57346] [Bug #8945] Numerics never be tainted'
+    b = 1 << 32
+    b *= b until Bignum === b
+    tainted = [0, 1.0, 1.72723e-77, b].select do |x|
+      Marshal.load(Marshal.dump(x).taint).tainted?
+    end
+    assert_empty(tainted.map {|x| [x, x.class]}, bug8945)
+  end
 end

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

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