Project

General

Profile

Bug #15577

FileUtils.remove_entry_secure() raises unexpected NameError

Added by Tietew (Toru Iwase) 6 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
[ruby-core:91362]

Description

How to reproduce

$ sudo mkdir /tmp/foobar
$ ruby -rfileutils -e 'FileUtils.remove_entry_secure("/tmp/foobar")'
Traceback (most recent call last):
        4: from -e:1:in `<main>'
        3: from /usr/local/anyenv/envs/rbenv/versions/2.6.1/lib/ruby/2.6.0/fileutils.rb:689:in `remove_entry_secure'
        2: from /usr/local/anyenv/envs/rbenv/versions/2.6.1/lib/ruby/2.6.0/fileutils.rb:689:in `open'
        1: from /usr/local/anyenv/envs/rbenv/versions/2.6.1/lib/ruby/2.6.0/fileutils.rb:695:in `block in remove_entry_secure'
/usr/local/anyenv/envs/rbenv/versions/2.6.1/lib/ruby/2.6.0/fileutils.rb:695:in `chown': Operation not permitted @ rb_file_chown - /tmp/foobar/. (Errno::EPERM)
        2: from -e:1:in `<main>'
        1: from /usr/local/anyenv/envs/rbenv/versions/2.6.1/lib/ruby/2.6.0/fileutils.rb:688:in `remove_entry_secure'
/usr/local/anyenv/envs/rbenv/versions/2.6.1/lib/ruby/2.6.0/fileutils.rb:698:in `rescue in remove_entry_secure': uninitialized constant FileUtils::EISDIR (NameError)

Expected

Raises Errno::EPERM

Actual

Raises NameError (uninitialized constant FileUtils::EISDIR)

Patch

diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index dc7261857b..8981ef98e8 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -695,7 +695,7 @@ def remove_entry_secure(path, force = false)
         f.chown euid, -1
         f.chmod 0700
       }
-    rescue EISDIR # JRuby in non-native mode can't open files as dirs
+    rescue Errno::EISDIR # JRuby in non-native mode can't open files as dirs
       File.lstat(dot_file).tap {|fstat|
         unless fu_stat_identical_entry?(st, fstat)
           # symlink (TOC-to-TOU attack?)

Versions

  • 2.3.8: Good
  • 2.4.5: Good
  • 2.5.3: Good
  • 2.6.1: Bad
  • trunk: Bad

Associated revisions

Revision cb5a3298
Added by nobu (Nobuyoshi Nakada) 6 months ago

Fix exception namespace

  • lib/fileutils.rb (remove_entry_secure): EISDIR is under the Errno namespace. [ruby-core:91362] [Bug #15577]

From: Tietew (Toru Iwase) tietew@tietew.net

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66972 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 66972
Added by nobu (Nobuyoshi Nakada) 6 months ago

Fix exception namespace

  • lib/fileutils.rb (remove_entry_secure): EISDIR is under the Errno namespace. [ruby-core:91362] [Bug #15577]

From: Tietew (Toru Iwase) tietew@tietew.net

Revision 66973
Added by nobu (Nobuyoshi Nakada) 6 months ago

Run r66972 assertion only when a sticky-bit makes sense

Revision 470a7046
Added by naruse (Yui NARUSE) 4 months ago

merge revision(s) 66972: [Backport #15577]

    Fix exception namespace

    * lib/fileutils.rb (remove_entry_secure): EISDIR is under the
      Errno namespace.  [ruby-core:91362] [Bug #15577]

    From: Tietew (Toru Iwase) <tietew@tietew.net>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67177
Added by naruse (Yui NARUSE) 4 months ago

merge revision(s) 66972: [Backport #15577]

Fix exception namespace

* lib/fileutils.rb (remove_entry_secure): EISDIR is under the
  Errno namespace.  [ruby-core:91362] [Bug #15577]

From: Tietew (Toru Iwase) <tietew@tietew.net>

Revision 50a334d8
Added by naruse (Yui NARUSE) 4 months ago

merge revision(s) 66973: [Backport #15577]

    Run r66972 assertion only when a sticky-bit makes sense

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 67210
Added by naruse (Yui NARUSE) 4 months ago

merge revision(s) 66973: [Backport #15577]

Run r66972 assertion only when a sticky-bit makes sense

History

#1

Updated by nobu (Nobuyoshi Nakada) 6 months ago

  • Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN to 2.4: DONTNEED, 2.5: DONTNEED, 2.6: REQUIRED
#2

Updated by nobu (Nobuyoshi Nakada) 6 months ago

  • Status changed from Open to Closed

Applied in changeset trunk|r66972.


Fix exception namespace

  • lib/fileutils.rb (remove_entry_secure): EISDIR is under the Errno namespace. [ruby-core:91362] [Bug #15577]

From: Tietew (Toru Iwase) tietew@tietew.net

Updated by naruse (Yui NARUSE) 4 months ago

  • Backport changed from 2.4: DONTNEED, 2.5: DONTNEED, 2.6: REQUIRED to 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE

ruby_2_6 r67177 merged revision(s) 66972.

Also available in: Atom PDF