Permalink
Browse files

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_2@63017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
unak committed Mar 28, 2018
1 parent 143eb22 commit e9ddf2ba41a0bffe1047e33576affd48808c5d0b
Showing with 68 additions and 2 deletions.
  1. +4 −0 ChangeLog
  2. +2 −0 lib/tmpdir.rb
  3. +27 −1 test/test_tempfile.rb
  4. +34 −0 test/test_tmpdir.rb
  5. +1 −1 version.h
@@ -1,3 +1,7 @@
Wed Mar 28 23:30:32 2018 SHIBATA Hiroshi <hsbt@ruby-lang.org>

Ignore file separator from tmpfile/tmpdir name.

Wed Mar 28 23:27:23 2018 Nobuyoshi Nakada <nobu@ruby-lang.org>

dir.c: check NUL bytes
@@ -108,8 +108,10 @@ def tmpdir
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)}"
path << "-#{n}" if n
@@ -339,5 +339,31 @@ def test_create_without_block
f.close if f && !f.closed?
File.unlink path if 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
@@ -36,4 +36,38 @@ def test_mktmpdir_nil
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

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
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.2.10"
#define RUBY_RELEASE_DATE "2018-03-28"
#define RUBY_PATCHLEVEL 483
#define RUBY_PATCHLEVEL 484

#define RUBY_RELEASE_YEAR 2018
#define RUBY_RELEASE_MONTH 3

0 comments on commit e9ddf2b

Please sign in to comment.