Skip to content

Commit

Permalink
* lib/fileutils.rb (FileUtils::remove_entry_secure): there is a
Browse files Browse the repository at this point in the history
  race condition in the case where the given path is a directory,
  and some other user can move that directory, and create a
  symlink while this method is executing.
  Reported by: Nicholas Jefferson <nicholas at pythonic.com.au>


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30896 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
shyouhei committed Feb 18, 2011
1 parent 80466e3 commit c1afbd3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Fri Feb 18 19:31:31 2011 Shugo Maeda <[email protected]>

* lib/fileutils.rb (FileUtils::remove_entry_secure): there is a
race condition in the case where the given path is a directory,
and some other user can move that directory, and create a
symlink while this method is executing.
Reported by: Nicholas Jefferson <nicholas at pythonic.com.au>

Fri Feb 18 00:28:39 2011 CHIKANAGA Tomoyuki <[email protected]>

* compile.c (get_exception_sym2type): guard temporary object from GC.
Expand Down
13 changes: 9 additions & 4 deletions lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,10 @@ def rm_rf(list, options = {})
# removing directories. This requires the current process is the
# owner of the removing whole directory tree, or is the super user (root).
#
# WARNING: You must ensure that *ALL* parent directories are not
# world writable. Otherwise this method does not work.
# Only exception is temporary directory like /tmp and /var/tmp,
# whose permission is 1777.
# WARNING: You must ensure that *ALL* parent directories cannot be
# moved by other untrusted users. For example, parent directories
# should not be owned by untrusted users, and should not be world
# writable except when the sticky bit set.
#
# WARNING: Only the owner of the removing directory tree, or Unix super
# user (root) should invoke this method. Otherwise this method does not
Expand Down Expand Up @@ -713,6 +713,11 @@ def remove_entry_secure(path, force = false)
end
f.chown euid, -1
f.chmod 0700
unless fu_stat_identical_entry?(st, File.lstat(fullpath))
# TOC-to-TOU attack?
File.unlink fullpath
return
end
}
# ---- tree root is frozen ----
root = Entry_.new(path)
Expand Down

0 comments on commit c1afbd3

Please sign in to comment.