[前][次][番号順一覧][スレッド一覧]

ruby-changes:66280

From: aycabta <ko1@a...>
Date: Fri, 21 May 2021 13:42:14 +0900 (JST)
Subject: [ruby-changes:66280] b1c73f239f (master): [ruby/rdoc] Use File.open to fix the OS Command Injection vulnerability in CVE-2021-31799

https://git.ruby-lang.org/ruby.git/commit/?id=b1c73f239f

From b1c73f239fe9af97de837331849f55d67c27561e Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Sun, 2 May 2021 20:52:23 +0900
Subject: [ruby/rdoc] Use File.open to fix the OS Command Injection
 vulnerability in CVE-2021-31799

https://github.com/ruby/rdoc/commit/a7f5d6ab88
---
 lib/rdoc/rdoc.rb            |  2 +-
 test/rdoc/test_rdoc_rdoc.rb | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index 680a861..904625f 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -444,7 +444,7 @@ The internal error was: https://github.com/ruby/ruby/blob/trunk/lib/rdoc/rdoc.rb#L444
     files.reject do |file, *|
       file =~ /\.(?:class|eps|erb|scpt\.txt|svg|ttf|yml)$/i or
         (file =~ /tags$/i and
-         open(file, 'rb') { |io|
+         File.open(file, 'rb') { |io|
            io.read(100) =~ /\A(\f\n[^,]+,\d+$|!_TAG_)/
          })
     end
diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb
index 3910dd4..a83d5a1 100644
--- a/test/rdoc/test_rdoc_rdoc.rb
+++ b/test/rdoc/test_rdoc_rdoc.rb
@@ -456,6 +456,18 @@ class TestRDocRDoc < RDoc::TestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_rdoc.rb#L456
     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
     Dir.mktmpdir {|d|
       path = File.join d, 'testdir'
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]