summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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|
{#