From 83c337f29a1f2d96ad40449364245451cf89b140 Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 2 Dec 2013 14:06:39 +0000 Subject: merge revision(s) 43853: [Backport #9157] * file.c (rb_readlink): fix buffer overflow on a long symlink. since rb_str_modify_expand() expands from its length but not its capacity, need to set the length properly for each expansion. [ruby-core:58592] [Bug #9157] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@43959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_file_exhaustive.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index beeab8dc29..5f98042c32 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -391,6 +391,24 @@ class TestFileExhaustive < Test::Unit::TestCase rescue NotImplementedError end + def test_readlink_long_path + return unless @symlinkfile + bug9157 = '[ruby-core:58592] [Bug #9157]' + assert_separately(["-", @symlinkfile, bug9157], <<-"end;") + symlinkfile, bug9157 = *ARGV + 100.step(1000, 100) do |n| + File.unlink(symlinkfile) + link = "foo"*n + begin + File.symlink(link, symlinkfile) + rescue Errno::ENAMETOOLONG + break + end + assert_equal(link, File.readlink(symlinkfile), bug9157) + end + end; + end + def test_unlink assert_equal(1, File.unlink(@file)) make_file("foo", @file) -- cgit v1.2.3