From d61dfcc7939199e19c2034c422f3473142c6d0a4 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 14 Jul 2012 07:04:28 +0000 Subject: [PATCH] array.c: no infection by unused separator * array.c (rb_ary_join): should not infected by separator if it is not used. [ruby-core:42161][Bug #5902] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 4 ++-- test/ruby/test_array.rb | 13 +++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78483e50dd..27efd3dc89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jul 14 16:04:24 2012 Nobuyoshi Nakada + + * array.c (rb_ary_join): should not infected by separator if it is not + used. [ruby-core:42161][Bug #5902] + Sat Jul 14 02:31:55 2012 Nobuyoshi Nakada * include/ruby/intern.h (rb_thread_blocking_region): fix declarations diff --git a/array.c b/array.c index 7b2418a103..89b5f98688 100644 --- a/array.c +++ b/array.c @@ -1768,8 +1768,8 @@ rb_ary_join(VALUE ary, VALUE sep) VALUE val, tmp, result; if (RARRAY_LEN(ary) == 0) return rb_usascii_str_new(0, 0); - if (OBJ_TAINTED(ary) || OBJ_TAINTED(sep)) taint = TRUE; - if (OBJ_UNTRUSTED(ary) || OBJ_UNTRUSTED(sep)) untrust = TRUE; + if (OBJ_TAINTED(ary)) taint = TRUE; + if (OBJ_UNTRUSTED(ary)) untrust = TRUE; if (!NIL_P(sep)) { StringValue(sep); diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 16875894ef..a4fda99474 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -920,6 +920,19 @@ class TestArray < Test::Unit::TestCase assert_equal(true, s.tainted?) assert_equal(true, s.untrusted?) + bug5902 = '[ruby-core:42161]' + sep = ":".taint.untrust + + s = @cls[].join(sep) + assert_equal(false, s.tainted?, bug5902) + assert_equal(false, s.untrusted?, bug5902) + s = @cls[1].join(sep) + assert_equal(false, s.tainted?, bug5902) + assert_equal(false, s.untrusted?, bug5902) + s = @cls[1, 2].join(sep) + assert_equal(true, s.tainted?, bug5902) + assert_equal(true, s.untrusted?, bug5902) + e = ''.force_encoding('EUC-JP') u = ''.force_encoding('UTF-8') assert_equal(Encoding::US_ASCII, [[]].join.encoding)