From 3529cc45cb25630a109cb650d5813a1f2ba405cb Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 11 Jul 2018 23:59:10 -0400 Subject: eval: Fix -delete when following symlinks. Same bug as https://savannah.gnu.org/bugs/?46305. Please don't ever do this though. --- eval.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'eval.c') diff --git a/eval.c b/eval.c index a4ee5c5..9308a17 100644 --- a/eval.c +++ b/eval.c @@ -277,8 +277,21 @@ bool eval_delete(const struct expr *expr, struct eval_state *state) { } int flag = 0; - if (ftwbuf->typeflag == BFTW_DIR) { - flag |= AT_REMOVEDIR; + if (ftwbuf->at_flags & AT_SYMLINK_NOFOLLOW) { + if (ftwbuf->typeflag == BFTW_DIR) { + flag |= AT_REMOVEDIR; + } + } else { + // We need to know the actual type of the path, not what it points to + struct bfs_stat sb; + if (bfs_stat(ftwbuf->at_fd, ftwbuf->at_path, ftwbuf->at_flags | AT_SYMLINK_NOFOLLOW, 0, &sb) == 0) { + if (S_ISDIR(sb.mode)) { + flag |= AT_REMOVEDIR; + } + } else { + eval_error(state); + return false; + } } if (unlinkat(ftwbuf->at_fd, ftwbuf->at_path, flag) != 0) { -- cgit v1.2.3