mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/rdoc] Use File.open to fix the OS Command Injection vulnerability in CVE-2021-31799
https://github.com/ruby/rdoc/commit/a7f5d6ab88
This commit is contained in:
parent
9edad0df74
commit
b1c73f239f
2 changed files with 13 additions and 1 deletions
|
@ -444,7 +444,7 @@ The internal error was:
|
||||||
files.reject do |file, *|
|
files.reject do |file, *|
|
||||||
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
|
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
|
||||||
(file =~ /tags$/i and
|
(file =~ /tags$/i and
|
||||||
open(file, 'rb') { |io|
|
File.open(file, 'rb') { |io|
|
||||||
io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
|
io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
@ -456,6 +456,18 @@ class TestRDocRDoc < RDoc::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_remove_unparseable_CVE_2021_31799
|
||||||
|
temp_dir do
|
||||||
|
file_list = ['| touch evil.txt && echo tags']
|
||||||
|
file_list.each do |f|
|
||||||
|
FileUtils.touch f
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal file_list, @rdoc.remove_unparseable(file_list)
|
||||||
|
assert_equal file_list, Dir.children('.')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_setup_output_dir
|
def test_setup_output_dir
|
||||||
Dir.mktmpdir {|d|
|
Dir.mktmpdir {|d|
|
||||||
path = File.join d, 'testdir'
|
path = File.join d, 'testdir'
|
||||||
|
|
Loading…
Add table
Reference in a new issue