ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: naruse@airemix.jp
To: ruby-core@ruby-lang.org
Subject: [ruby-core:91693] [Ruby trunk Bug#15577] FileUtils.remove_entry_secure() raises unexpected NameError
Date: Wed, 06 Mar 2019 07:38:01 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-76958.20190306073759.2421e25d7ec05307@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15577.20190131120637@ruby-lang.org

Issue #15577 has been updated by naruse (Yui NARUSE).

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.

----------------------------------------
Bug #15577: FileUtils.remove_entry_secure() raises unexpected NameError
https://bugs.ruby-lang.org/issues/15577#change-76958

* Author: Tietew (Toru Iwase)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
* Backport: 2.4: DONTNEED, 2.5: DONTNEED, 2.6: DONE
----------------------------------------
## 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

``` 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



-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2019-03-06  7:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15577.20190131120637@ruby-lang.org>
2019-01-31 12:06 ` [ruby-core:91362] [Ruby trunk Bug#15577] FileUtils.remove_entry_secure() raises unexpected NameError tietew
2019-03-06  7:38 ` naruse [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-76958.20190306073759.2421e25d7ec05307@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).