diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-18 11:48:02 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-02-18 11:48:02 +0000 |
commit | 452c5aff0f25ca24cffeaa98c29fd6cca4952197 (patch) | |
tree | 3410a08b5c90afa3bb17acfe9f0be39ac8f8e4be | |
parent | c13f628759ebceb5f7e02f48236774b49f1e4251 (diff) |
merge revision(s) 30896:
* 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>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@30905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | lib/fileutils.rb | 13 |
2 files changed, 17 insertions, 4 deletions
@@ -1,3 +1,11 @@ +Fri Feb 18 20:46:55 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 20:02:29 2011 Shugo Maeda <[email protected]> * test/ruby/test_exception.rb (TestException::test_to_s_taintness_propagation): diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 2105a7721e..e0fa868875 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -668,10 +668,10 @@ module FileUtils # 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 @@ -714,6 +714,11 @@ module FileUtils 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) |