Skip to content

Commit a7f5d6a

Browse files
committed
Use File.open to fix the OS Command Injection vulnerability in CVE-2021-31799
1 parent 06112d5 commit a7f5d6a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/rdoc/rdoc.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def remove_unparseable files
443443
files.reject do |file, *|
444444
file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
445445
(file =~ /tags$/i and
446-
open(file, 'rb') { |io|
446+
File.open(file, 'rb') { |io|
447447
io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
448448
})
449449
end

test/rdoc/test_rdoc_rdoc.rb

+12
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,18 @@ def test_remove_unparseable_tags_vim
456456
end
457457
end
458458

459+
def test_remove_unparseable_CVE_2021_31799
460+
temp_dir do
461+
file_list = ['| touch evil.txt && echo tags']
462+
file_list.each do |f|
463+
FileUtils.touch f
464+
end
465+
466+
assert_equal file_list, @rdoc.remove_unparseable(file_list)
467+
assert_equal file_list, Dir.children('.')
468+
end
469+
end
470+
459471
def test_setup_output_dir
460472
Dir.mktmpdir {|d|
461473
path = File.join d, 'testdir'

0 commit comments

Comments
 (0)