ruby-changes:47983
From: nobu <ko1@a...>
Date: Mon, 2 Oct 2017 15:46:47 +0900 (JST)
Subject: [ruby-changes:47983] nobu:r60097 (trunk): io.c: check null char
nobu 2017-10-02 15:46:42 +0900 (Mon, 02 Oct 2017) New Revision: 60097 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60097 Log: 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] Modified files: trunk/io.c trunk/test/ruby/test_argf.rb Index: io.c =================================================================== --- io.c (revision 60096) +++ io.c (revision 60097) @@ -12224,10 +12224,10 @@ argf_inplace_mode_set(VALUE argf, VALUE https://github.com/ruby/ruby/blob/trunk/io.c#L12224 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; } Index: test/ruby/test_argf.rb =================================================================== --- test/ruby/test_argf.rb (revision 60096) +++ test/ruby/test_argf.rb (revision 60097) @@ -310,6 +310,12 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L310 }; 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| {# -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/