f70500
From 216e73a58ed85014d547cbc89006ff2a987bab1f Mon Sep 17 00:00:00 2001
f70500
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
f70500
Date: Wed, 17 Oct 2018 15:09:24 +0000
f70500
Subject: [PATCH] merge revision(s) 65125:
f70500
f70500
	infect taint flag on Array#pack and String#unpack
f70500
	with the directives "B", "b", "H" and "h".
f70500
f70500
		* pack.c (pack_pack, pack_unpack_internal): infect taint flag.
f70500
f70500
		* test/ruby/test_pack.rb: add test for above.
f70500
f70500
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@65130 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
f70500
---
f70500
 pack.c                 |  8 ++++++++
f70500
 test/ruby/test_pack.rb | 15 +++++++++++++++
f70500
 2 files changed, 23 insertions(+)
f70500
f70500
diff --git a/pack.c b/pack.c
f70500
index d304dd2eea..b64c0f64cb 100644
f70500
--- a/pack.c
f70500
+++ b/pack.c
f70500
@@ -944,6 +944,7 @@ pack_pack(VALUE ary, VALUE fmt)
f70500
 	    StringValue(from);
f70500
 	    ptr = RSTRING_PTR(from);
f70500
 	    plen = RSTRING_LEN(from);
f70500
+	    OBJ_INFECT(res, from);
f70500
 
f70500
 	    if (len == 0 && type == 'm') {
f70500
 		encodes(res, ptr, plen, type, 0);
f70500
@@ -971,6 +972,7 @@ pack_pack(VALUE ary, VALUE fmt)
f70500
 
f70500
 	  case 'M':		/* quoted-printable encoded string */
f70500
 	    from = rb_obj_as_string(NEXTFROM);
f70500
+	    OBJ_INFECT(res, from);
f70500
 	    if (len <= 1)
f70500
 		len = 72;
f70500
 	    qpencode(res, from, len);
f70500
@@ -996,6 +998,8 @@ pack_pack(VALUE ary, VALUE fmt)
f70500
 		}
f70500
 		else {
f70500
 		    t = StringValuePtr(from);
f70500
+		    OBJ_INFECT(res, from);
f70500
+		    rb_obj_taint(from);
f70500
 		}
f70500
 		if (!associates) {
f70500
 		    associates = rb_ary_new();
f70500
@@ -1487,6 +1491,7 @@ pack_unpack(VALUE str, VALUE fmt)
f70500
 		    len = (send - s) * 8;
f70500
 		bits = 0;
f70500
 		UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
f70500
+		OBJ_INFECT(bitstr, str);
f70500
 		t = RSTRING_PTR(bitstr);
f70500
 		for (i=0; i
f70500
 		    if (i & 7) bits >>= 1;
f70500
@@ -1507,6 +1512,7 @@ pack_unpack(VALUE str, VALUE fmt)
f70500
 		    len = (send - s) * 8;
f70500
 		bits = 0;
f70500
 		UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
f70500
+		OBJ_INFECT(bitstr, str);
f70500
 		t = RSTRING_PTR(bitstr);
f70500
 		for (i=0; i
f70500
 		    if (i & 7) bits <<= 1;
f70500
@@ -1527,6 +1533,7 @@ pack_unpack(VALUE str, VALUE fmt)
f70500
 		    len = (send - s) * 2;
f70500
 		bits = 0;
f70500
 		UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
f70500
+		OBJ_INFECT(bitstr, str);
f70500
 		t = RSTRING_PTR(bitstr);
f70500
 		for (i=0; i
f70500
 		    if (i & 1)
f70500
@@ -1549,6 +1556,7 @@ pack_unpack(VALUE str, VALUE fmt)
f70500
 		    len = (send - s) * 2;
f70500
 		bits = 0;
f70500
 		UNPACK_PUSH(bitstr = rb_usascii_str_new(0, len));
f70500
+		OBJ_INFECT(bitstr, str);
f70500
 		t = RSTRING_PTR(bitstr);
f70500
 		for (i=0; i
f70500
 		    if (i & 1)
f70500
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
f70500
index 8ca34051a9..9bf1f1b064 100644
f70500
--- a/test/ruby/test_pack.rb
f70500
+++ b/test/ruby/test_pack.rb
f70500
@@ -709,4 +709,19 @@ EXPECTED
f70500
     $VERBOSE = verbose
f70500
   end
f70500
 
f70500
+  def test_pack_infection
f70500
+    tainted_array_string = ["123456"]
f70500
+    tainted_array_string.first.taint
f70500
+    ['a', 'A', 'Z', 'B', 'b', 'H', 'h', 'u', 'M', 'm', 'P', 'p'].each do |f|
f70500
+      assert_predicate(tainted_array_string.pack(f), :tainted?)
f70500
+    end
f70500
+  end
f70500
+
f70500
+  def test_unpack_infection
f70500
+    tainted_string = "123456"
f70500
+    tainted_string.taint
f70500
+    ['a', 'A', 'Z', 'B', 'b', 'H', 'h', 'u', 'M', 'm'].each do |f|
f70500
+      assert_predicate(tainted_string.unpack(f).first, :tainted?)
f70500
+    end
f70500
+  end
f70500
 end
f70500
-- 
f70500
2.17.1
f70500