summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-02 14:06:39 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-02 14:06:39 +0000
commit83c337f29a1f2d96ad40449364245451cf89b140 (patch)
tree9e0b265035691eeb84e8b1bf1516af6d9dac8d0b
parentdd7ec71b125d19d0afcfdd56ec5c29ce509e4201 (diff)
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
-rw-r--r--ChangeLog7
-rw-r--r--file.c1
-rw-r--r--test/ruby/test_file_exhaustive.rb18
-rw-r--r--version.h8
4 files changed, 30 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 209ed8cb69..8c51baf872 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Mon Dec 2 22:53:05 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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]
+
Fri Nov 29 00:31:46 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* common.mk (Doxyfile): tool/file2lastrev.rb needs running with
diff --git a/file.c b/file.c
index 53ed9509a0..9dda3fc70d 100644
--- a/file.c
+++ b/file.c
@@ -2531,6 +2531,7 @@ rb_readlink(VALUE path)
) {
rb_str_modify_expand(v, size);
size *= 2;
+ rb_str_set_len(v, size);
}
if (rv < 0) {
rb_str_resize(v, 0);
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)
diff --git a/version.h b/version.h
index 6d4a31fdcd..a9d4df1eb5 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.0.0"
-#define RUBY_RELEASE_DATE "2013-11-29"
-#define RUBY_PATCHLEVEL 354
+#define RUBY_RELEASE_DATE "2013-12-02"
+#define RUBY_PATCHLEVEL 355
#define RUBY_RELEASE_YEAR 2013
-#define RUBY_RELEASE_MONTH 11
-#define RUBY_RELEASE_DAY 29
+#define RUBY_RELEASE_MONTH 12
+#define RUBY_RELEASE_DAY 2
#include "ruby/version.h"