diff options
author | Martin Pitt <martinpitt@users.noreply.github.com> | 2017-04-29 21:19:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-29 21:19:24 +0200 |
commit | 815e542b7caee5166668180c8014e29bfe3bf1f8 (patch) | |
tree | afba4ca09ba29a81ef8f0d8a1850df011a62d36f /src/basic/rm-rf.c | |
parent | 5b3cc0c86aeddd4615e7e28e79aa89e5b77a6507 (diff) | |
parent | d8c92e8bc7351f553936b5235e1922c18ebd817a (diff) |
Merge pull request #5809 from keszybz/glob-safe
Implement `safe_glob` that ignores "." and ".."
Diffstat (limited to 'src/basic/rm-rf.c')
-rw-r--r-- | src/basic/rm-rf.c | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c index bdaca264ff..ff040e7a55 100644 --- a/src/basic/rm-rf.c +++ b/src/basic/rm-rf.c @@ -182,18 +182,11 @@ int rm_rf(const char *path, RemoveFlags flags) { /* We refuse to clean the root file system with this * call. This is extra paranoia to never cause a really * seriously broken system. */ - if (path_equal(path, "/")) { + if (path_equal_or_files_same(path, "/")) { log_error("Attempted to remove entire root file system, and we can't allow that."); return -EPERM; } - /* Another safe-check. Removing "/path/.." could easily remove entire root as well. - * It's especially easy to do using globs in tmpfiles, like "/path/.*", which the glob() - * function expands to both "/path/." and "/path/..". - * Return -EINVAL to be consistent with rmdir("/path/."). */ - if (endswith(path, "/..") || endswith(path, "/../")) - return -EINVAL; - if ((flags & (REMOVE_SUBVOLUME|REMOVE_ROOT|REMOVE_PHYSICAL)) == (REMOVE_SUBVOLUME|REMOVE_ROOT|REMOVE_PHYSICAL)) { /* Try to remove as subvolume first */ r = btrfs_subvol_remove(path, BTRFS_REMOVE_RECURSIVE|BTRFS_REMOVE_QUOTA); |