summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-28 10:52:33 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-28 10:52:33 +0000
commit2395bb1159ebd26f5138e7f3acf8d5332b170543 (patch)
tree6feac4b5ddf24798c21c1f106d773a26ac8992c0
parentaf30b5b5a8e827e76fb9de644551f5c5589ef6bb (diff)
merge revision(s) 62990:
Ignore file separator from tmpfile/tmpdir name. From: SHIBATA Hiroshi <hsbt@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--lib/tmpdir.rb2
-rw-r--r--test/test_tempfile.rb28
-rw-r--r--test/test_tmpdir.rb17
-rw-r--r--version.h2
4 files changed, 47 insertions, 2 deletions
diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb
index d12afa1ae6..13ed580eb4 100644
--- a/lib/tmpdir.rb
+++ b/lib/tmpdir.rb
@@ -109,8 +109,10 @@ class Dir
def make_tmpname((prefix, suffix), n)
prefix = (String.try_convert(prefix) or
raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
+ prefix = prefix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
suffix &&= (String.try_convert(suffix) or
raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
+ suffix &&= suffix.delete("#{File::SEPARATOR}#{File::ALT_SEPARATOR}")
t = Time.now.strftime("%Y%m%d")
path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}".dup
path << "-#{n}" if n
diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb
index a31ea67fd0..ff61cc5076 100644
--- a/test/test_tempfile.rb
+++ b/test/test_tempfile.rb
@@ -365,5 +365,31 @@ puts Tempfile.new('foo').path
}
assert_file.not_exist?(path)
end
-end
+ TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
+
+ def test_open_traversal_dir
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
+ t = Tempfile.open([TRAVERSAL_PATH, 'foo'])
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
+ assert_equal expect, actual
+ ensure
+ t.close!
+ end
+
+ def test_new_traversal_dir
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
+ t = Tempfile.new(TRAVERSAL_PATH + 'foo')
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
+ assert_equal expect, actual
+ ensure
+ t.close!
+ end
+
+ def test_create_traversal_dir
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
+ Tempfile.create(TRAVERSAL_PATH + 'foo')
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
+ assert_equal expect, actual
+ end
+end
diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb
index 4fc4bca4d5..c9e85aeae2 100644
--- a/test/test_tmpdir.rb
+++ b/test/test_tmpdir.rb
@@ -56,4 +56,21 @@ class TestTmpdir < Test::Unit::TestCase
assert_kind_of(String, d)
}
end
+
+ TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/'
+ TRAVERSAL_PATH.delete!(':') if /mswin|mingw/ =~ RUBY_PLATFORM
+
+ def test_mktmpdir_traversal
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
+ Dir.mktmpdir(TRAVERSAL_PATH + 'foo')
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
+ assert_equal expect, actual
+ end
+
+ def test_mktmpdir_traversal_array
+ expect = Dir.glob(TRAVERSAL_PATH + '*').count
+ Dir.mktmpdir([TRAVERSAL_PATH, 'foo'])
+ actual = Dir.glob(TRAVERSAL_PATH + '*').count
+ assert_equal expect, actual
+ end
end
diff --git a/version.h b/version.h
index 1141c17130..f8d588c2a9 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.4.4"
#define RUBY_RELEASE_DATE "2018-03-28"
-#define RUBY_PATCHLEVEL 289
+#define RUBY_PATCHLEVEL 290
#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 3