aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-02 06:46:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-02 06:46:42 +0000
commit8148b7013c1b08df4fb7bd87bfc699f1f929e540 (patch)
tree466b40286a32eda2c5329fa753fef330aa9e12fb
parent85847e78a0614d1f3373f22811ec6562fc0c2dc5 (diff)
downloadruby-8148b7013c1b08df4fb7bd87bfc699f1f929e540.tar.gz
io.c: check null char
* io.c (ruby_set_inplace_mode): check if null is contained. based on the patch by tommy (Masahiro Tomita) in [ruby-dev:50272]. [Bug #13960] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--io.c4
-rw-r--r--test/ruby/test_argf.rb6
2 files changed, 8 insertions, 2 deletions
diff --git a/io.c b/io.c
index 1254e92363..6226108ad6 100644
--- a/io.c
+++ b/io.c
@@ -12224,10 +12224,10 @@ argf_inplace_mode_set(VALUE argf, VALUE val)
ARGF.inplace = 0;
}
else {
- StringValue(val);
+ const char *suffix = StringValueCStr(val);
if (ARGF.inplace) free(ARGF.inplace);
ARGF.inplace = 0;
- ARGF.inplace = strdup(RSTRING_PTR(val));
+ ARGF.inplace = strdup(suffix);
}
return argf;
}
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index bc5c67d0d8..a112cf3e84 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -310,6 +310,12 @@ class TestArgf < Test::Unit::TestCase
};
end
+ def test_inplace_invalid_backup
+ assert_raise(ArgumentError, '[ruby-dev:50272] [Bug #13960]') {
+ ARGF.inplace_mode = "a\0"
+ }
+ end
+
def test_encoding
ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
{#