ruby-changes:33589
From: nobu <ko1@a...>
Date: Tue, 22 Apr 2014 23:14:38 +0900 (JST)
Subject: [ruby-changes:33589] nobu:r45670 (trunk): stringio.c: use rb_str_append
nobu 2014-04-22 23:14:30 +0900 (Tue, 22 Apr 2014) New Revision: 45670 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45670 Log: stringio.c: use rb_str_append * ext/stringio/stringio.c (strio_write): use rb_str_append to reuse coderange bits and keep taintedness. [ruby-dev:48118] [Bug #9769] Modified files: trunk/ChangeLog trunk/ext/stringio/stringio.c trunk/test/stringio/test_stringio.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45669) +++ ChangeLog (revision 45670) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Apr 22 23:14:28 2014 Nobuyoshi Nakada <nobu@r...> + + * ext/stringio/stringio.c (strio_write): use rb_str_append to + reuse coderange bits and keep taintedness. + [ruby-dev:48118] [Bug #9769] + Tue Apr 22 22:15:51 2014 NAKAMURA Usaku <usa@r...> * file.c (rb_io_statfs): need to define even if the system doesn't have Index: ext/stringio/stringio.c =================================================================== --- ext/stringio/stringio.c (revision 45669) +++ ext/stringio/stringio.c (revision 45670) @@ -1170,7 +1170,6 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/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,7 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1185 ptr->pos = olen; } if (ptr->pos == olen) { - rb_enc_str_buf_cat(ptr->string, RSTRING_PTR(str), len, enc); + rb_str_append(ptr->string, str); } else { strio_extend(ptr, ptr->pos, len); @@ -1194,6 +1193,7 @@ strio_write(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1193 OBJ_INFECT(ptr->string, str); } OBJ_INFECT(ptr->string, self); + RB_GC_GUARD(str); ptr->pos += len; return LONG2NUM(len); } Index: test/stringio/test_stringio.rb =================================================================== --- test/stringio/test_stringio.rb (revision 45669) +++ test/stringio/test_stringio.rb (revision 45670) @@ -119,6 +119,17 @@ class TestStringIO < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/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_mode_error f = StringIO.new("", "r") assert_raise(IOError) { f.write("foo") } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/