ruby-changes:35024
From: nagachika <ko1@a...>
Date: Fri, 8 Aug 2014 23:58:43 +0900 (JST)
Subject: [ruby-changes:35024] nagachika:r47106 (ruby_2_1): merge revision(s) r45676, r45677: [Backport #9769]
nagachika 2014-08-08 23:58:32 +0900 (Fri, 08 Aug 2014) New Revision: 47106 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47106 Log: merge revision(s) r45676,r45677: [Backport #9769] stringio.c: move GC guard * ext/stringio/stringio.c (strio_write): move GC guard after the last using position. * ext/stringio/stringio.c (strio_write): use rb_str_append to reuse coderange bits other than ASCII-8BIT, and keep taintedness. [ruby-dev:48118] [Bug #9769] Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/ext/stringio/stringio.c branches/ruby_2_1/test/stringio/test_stringio.rb branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 47105) +++ ruby_2_1/ChangeLog (revision 47106) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Fri Aug 8 23:36:01 2014 Nobuyoshi Nakada <nobu@r...> + + * ext/stringio/stringio.c (strio_write): use rb_str_append to + reuse coderange bits other than ASCII-8BIT, and keep + taintedness. [ruby-dev:48118] [Bug #9769] + Mon Aug 4 01:29:57 2014 Nobuyoshi Nakada <nobu@r...> * hash.c (env_shift): fix memory leak on Windows, free environment Index: ruby_2_1/ext/stringio/stringio.c =================================================================== --- ruby_2_1/ext/stringio/stringio.c (revision 47105) +++ ruby_2_1/ext/stringio/stringio.c (revision 47106) @@ -1170,7 +1170,6 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/stringio/stringio.c#L1170 long len, olen; rb_encoding *enc, *enc2; - RB_GC_GUARD(str); if (!RB_TYPE_P(str, T_STRING)) str = rb_obj_as_string(str); enc = rb_enc_get(ptr->string); @@ -1186,7 +1185,13 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/stringio/stringio.c#L1185 ptr->pos = olen; } if (ptr->pos == olen) { - rb_enc_str_buf_cat(ptr->string, RSTRING_PTR(str), len, enc); + if (enc2 == rb_ascii8bit_encoding()) { + rb_enc_str_buf_cat(ptr->string, RSTRING_PTR(str), len, enc); + OBJ_INFECT(ptr->string, str); + } + else { + rb_str_buf_append(ptr->string, str); + } } else { strio_extend(ptr, ptr->pos, len); @@ -1194,6 +1199,7 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ext/stringio/stringio.c#L1199 OBJ_INFECT(ptr->string, str); } OBJ_INFECT(ptr->string, self); + RB_GC_GUARD(str); ptr->pos += len; return LONG2NUM(len); } Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 47105) +++ ruby_2_1/version.h (revision 47106) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.2" -#define RUBY_RELEASE_DATE "2014-08-04" -#define RUBY_PATCHLEVEL 195 +#define RUBY_RELEASE_DATE "2014-08-08" +#define RUBY_PATCHLEVEL 196 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 8 -#define RUBY_RELEASE_DAY 4 +#define RUBY_RELEASE_DAY 8 #include "ruby/version.h" Index: ruby_2_1/test/stringio/test_stringio.rb =================================================================== --- ruby_2_1/test/stringio/test_stringio.rb (revision 47105) +++ ruby_2_1/test/stringio/test_stringio.rb (revision 47106) @@ -119,6 +119,24 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/stringio/test_stringio.rb#L119 f.close unless f.closed? end + def test_write_infection + bug9769 = '[ruby-dev:48118] [Bug #9769]' + s = "".untaint + f = StringIO.new(s, "w") + f.print("bar".taint) + f.close + assert_predicate(s, :tainted?, bug9769) + ensure + f.close unless f.closed? + end + + def test_write_encoding + s = "".force_encoding(Encoding::UTF_8) + f = StringIO.new(s) + f.print("\u{3053 3093 306b 3061 306f ff01}".b) + assert_equal(Encoding::UTF_8, s.encoding, "honor the original encoding over ASCII-8BIT") + end + def test_mode_error f = StringIO.new("", "r") assert_raise(IOError) { f.write("foo") } Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r45676-45677 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/