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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 12 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy