ruby-changes:65378
From: usa <ko1@a...>
Date: Tue, 2 Mar 2021 20:37:57 +0900 (JST)
Subject: [ruby-changes:65378] 34768ea9df (ruby_2_6): merge revision(s) 2ecfb88e: [Backport #16918]
https://git.ruby-lang.org/ruby.git/commit/?id=34768ea9df From 34768ea9df63abd5fd9b10553bbd23da52365018 Mon Sep 17 00:00:00 2001 From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Tue, 2 Mar 2021 11:37:36 +0000 Subject: merge revision(s) 2ecfb88e: [Backport #16918] Correctly remove temporary directory if path yielded is mutated Another approach would be to freeze the string, but that could cause backwards compatibility issues. Fixes [Bug #16918] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/tmpdir.rb | 2 +- test/test_tmpdir.rb | 38 ++++++++++++++++++++++++++++---------- version.h | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/tmpdir.rb b/lib/tmpdir.rb index 87e53a8..9d61595 100644 --- a/lib/tmpdir.rb +++ b/lib/tmpdir.rb @@ -90,7 +90,7 @@ class Dir https://github.com/ruby/ruby/blob/trunk/lib/tmpdir.rb#L90 } if block_given? begin - yield path + yield path.dup ensure unless base stat = File.stat(File.dirname(path)) diff --git a/test/test_tmpdir.rb b/test/test_tmpdir.rb index 1e633d2..bede8c0 100644 --- a/test/test_tmpdir.rb +++ b/test/test_tmpdir.rb @@ -65,22 +65,40 @@ class TestTmpdir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_tmpdir.rb#L65 } end - TRAVERSAL_PATH = Array.new(Dir.pwd.split('/').count, '..').join('/') + Dir.pwd + '/' - TRAVERSAL_PATH.delete!(':') if /mswin|mingw/ =~ RUBY_PLATFORM + def test_mktmpdir_mutate + bug16918 = '[ruby-core:98563]' + assert_nothing_raised(bug16918) do + assert_mktmpdir_traversal do |traversal_path| + Dir.mktmpdir(traversal_path + 'foo') do |actual| + actual << "foo" + end + end + end + end def test_mktmpdir_traversal - expect = Dir.glob(TRAVERSAL_PATH + '*').count - Dir.mktmpdir(TRAVERSAL_PATH + 'foo') do - actual = Dir.glob(TRAVERSAL_PATH + '*').count - assert_equal expect, actual + assert_mktmpdir_traversal do |traversal_path| + Dir.mktmpdir(traversal_path + 'foo') do |actual| + actual + end end end def test_mktmpdir_traversal_array - expect = Dir.glob(TRAVERSAL_PATH + '*').count - Dir.mktmpdir([TRAVERSAL_PATH, 'foo']) do - actual = Dir.glob(TRAVERSAL_PATH + '*').count - assert_equal expect, actual + assert_mktmpdir_traversal do |traversal_path| + Dir.mktmpdir([traversal_path, 'foo']) do |actual| + actual + end + end + end + + def assert_mktmpdir_traversal + Dir.mktmpdir do |target| + target = target.chomp('/') + '/' + traversal_path = target.sub(/\A\w:/, '') # for DOSISH + traversal_path = Array.new(target.count('/')-2, '..').join('/') + traversal_path + actual = yield traversal_path + assert_not_send([File.absolute_path(actual), :start_with?, target]) end end end diff --git a/version.h b/version.h index 60974d0..616e6f3 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1 #define RUBY_VERSION "2.6.7" #define RUBY_RELEASE_DATE "2021-03-02" -#define RUBY_PATCHLEVEL 169 +#define RUBY_PATCHLEVEL 170 #define RUBY_RELEASE_YEAR 2021 #define RUBY_RELEASE_MONTH 3 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/