commit: 9dbdd338c8b63c3a73fdcdcd8b56c05d46992923
parent 9923552690ca482655f69012a9de7c28c4e9545d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 28 Mar 2024 02:42:13 +0100
cmd/rm: Don't follow symlinks for write-check
Diffstat:
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/cmd/rm.c b/cmd/rm.c
@@ -176,7 +176,7 @@ do_unlinkat(int fd, char *name, char *acc_path)
if(!force)
{
// FIXME: Terminal always considered to be present for tests reason
- if(faccessat(fd, name, W_OK, 0) != 0 || opt_i)
+ if(faccessat(fd, name, W_OK, AT_SYMLINK_NOFOLLOW) != 0 || opt_i)
if(!consentf("rm: Remove '%s' ? [y/N] ", acc_path)) return 0;
}
diff --git a/test-cmd/rm.t b/test-cmd/rm.t
@@ -69,9 +69,7 @@ POSIX rm(1p) step 2c, don't follow symlinks
$ ln -s 2c-origin/file 2c-symlinks/file
$ test -L 2c-symlinks/file
$ test -L 2c-symlinks/dir
- $ printf '%s\n' y y | rm -r 2c-symlinks
- rm: Remove '2c-symlinks/(dir|file)' \? \[y/N\] y (re)
- rm: Remove '2c-symlinks/(dir|file)' \? \[y/N\] y (re)
+ $ rm -r 2c-symlinks
$ test ! -e 2c-symlinks
$ test -d 2c-origin
$ test -f 2c-origin/file
@@ -130,3 +128,10 @@ POSIX, -f shouldn't return an error when no operands are passed
rm: missing operand
Usage: rm [-firRv] [files ...]
[1]
+
+Don't follow symlinks
+ $ touch bar
+ $ ln bar foo
+ $ rm foo
+ $ test -e bar
+ $ test ! -e foo