summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-08 14:58:32 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-08 14:58:32 +0000
commitc4e2581392ef828160b760488d52c36464b451e3 (patch)
tree6be994a8440e7de03ba76144b1007f3581389412
parent92d58cacaf93080c997f01075378a60e2bbb3f41 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47106 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--ext/stringio/stringio.c10
-rw-r--r--test/stringio/test_stringio.rb18
-rw-r--r--version.h6
4 files changed, 35 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index b55cdf5fec..7941d287a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Aug 8 23:36:01 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* hash.c (env_shift): fix memory leak on Windows, free environment
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index fb8e7ce3ea..1a12d298e1 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -1170,7 +1170,6 @@ strio_write(VALUE self, VALUE str)
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)
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)
OBJ_INFECT(ptr->string, str);
}
OBJ_INFECT(ptr->string, self);
+ RB_GC_GUARD(str);
ptr->pos += len;
return LONG2NUM(len);
}
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index c7db91aae1..3fbe2f7eca 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -119,6 +119,24 @@ class TestStringIO < Test::Unit::TestCase
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") }
diff --git a/version.h b/version.h
index 3a1ee2741d..d89750b948 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#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"