On 21/02/2023 12:45, Pádraig Brady wrote:
On 21/02/2023 02:59, Jim Meyering wrote:---------- Forwarded message --------- From: Jim Meyering <j...@meyering.net> Date: Mon, Feb 20, 2023 at 6:27 PM Subject: Re: Bug#1015273: coreutils: rm -d doesn't try to remove unreadable directories, lies in error message, with *fails to prompt* with -i To: наб <nabijaczlew...@nabijaczleweli.xyz>, <1015...@bugs.debian.org> Cc: Debian Bug Tracking System <sub...@bugs.debian.org>On Mon, Jul 18, 2022 at 12:21 PM наб <nabijaczlew...@nabijaczleweli.xyz> wrote:Package: coreutils Version: 8.32-4.1 Severity: normal Dear Maintainer, Fun one for ya: the baseline: -- >8 -- $ mkdir -p /tmp/psko $ rm -vid /tmp/psko rm: remove directory '/tmp/psko'? y removed directory '/tmp/psko' -- >8 -- Bug a: -- >8 -- $ mkdir -p /tmp/psko $ chmod -r /tmp/psko $ rm -vid /tmp/psko; echo $? rm: cannot remove '/tmp/psko': Directory not empty 1 -- >8 -- Absolutely 0 prompt, despite -i! That's very fun (and a POSIX violation)! Bug b: -- >8 -- $ strace rm -vid /tmp/psko 2>&1 | grep -v locale execve("/bin/rm", ["rm", "-vid", "/tmp/psko"], 0xff8fbc48 /* 24 vars */) = 0 /* ... */ arch_prctl(ARCH_SET_FS, 0xf7f9e240) = 0 mprotect(0xf7f8b000, 8192, PROT_READ) = 0 mprotect(0x40f000, 4096, PROT_READ) = 0 mprotect(0xf7fcd000, 8192, PROT_READ) = 0 munmap(0xf7f96000, 26859) = 0 brk(NULL) = 0xaa6000 brk(0xac7000) = 0xac7000 brk(0xac8000) = 0xac8000 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=3041504, ...}, AT_EMPTY_PATH) = 0 mmap(NULL, 2097152, PROT_READ, MAP_PRIVATE, 3, 0) = 0xf7a00000 mmap(NULL, 2596864, PROT_READ, MAP_PRIVATE, 3, 0x6d000) = 0xf7786000 close(3) = 0 ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0 newfstatat(AT_FDCWD, "/tmp/psko", {st_mode=S_IFDIR|0311, st_size=40, ...}, AT_SYMLINK_NOFOLLOW) = 0 openat(AT_FDCWD, "/tmp/psko", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_NOFOLLOW|O_DIRECTORY) = -1 EACCES (Permission denied) newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2996, ...}, AT_EMPTY_PATH) = 0 read(3, "# Locale name alias data base.\n#"..., 4096) = 2996 read(3, "", 4096) = 0 close(3) = 0 write(2, "rm: ", 4rm: ) = 4 write(2, "cannot remove '/tmp/psko'", 25cannot remove '/tmp/psko') = 25 newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=1433, ...}, AT_EMPTY_PATH) = 0 mmap(NULL, 1433, PROT_READ, MAP_PRIVATE, 3, 0) = 0xf7f9c000 close(3) = 0 write(2, ": Directory not empty", 21: Directory not empty) = 21 write(2, "\n", 1 ) = 1 lseek(0, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek) close(0) = 0 close(1) = 0 close(2) = 0 exit_group(1) = ? +++ exited with 1 +++ -- >8 -- Can you spot a rmdir(2) equivalent? I can't! So why does it lie and say that it tried to remove it? Also, the directory /isn't nonempty/! Bug c: -- >8 -- $ rmdir -v /tmp/psko/; echo $? rmdir: removing directory, '/tmp/psko/' 0 -- >8 -- And it's not there! Because, shockingly, there's nothing stopping you from removing it! So why on /earth/ is rm failing to prompt, failing to try to remove it, then lying that it had and failed with an obviously false errno? The same applies to just plain rm -d /tmp/psko (no -i) (except for bug a).Thank you for the bug report. I've attached a patch that fixes those bugs.lgtm modulo the commit summary line should start with rm: not rm ...
Also pushed the attached to fix a test hang noticed by George Valkov. cheers, Pádraig
From 995021cb0ce72ea9c235bbf71c69d3b96bfa84e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com> Date: Sun, 26 Feb 2023 18:10:41 +0000 Subject: [PATCH] tests: avoid hang in new test * tests/rm/empty-inacc.sh: Ensure we're not reading from stdin when we're relying on no prompt to proceed. Also change the file being tested so that a failure in one test doesn't impact following tests causing a framework failure. --- tests/rm/empty-inacc.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/rm/empty-inacc.sh b/tests/rm/empty-inacc.sh index 807ff4d1d..56f7ef345 100755 --- a/tests/rm/empty-inacc.sh +++ b/tests/rm/empty-inacc.sh @@ -39,23 +39,23 @@ mkdir -m a-r unreadable2 || framework_failure_ mkdir -m0 inacc2 || framework_failure_ # These would fail for coreutils-9.1 and prior. -rm -d unreadable2 || fail=1 +rm -d unreadable2 < /dev/null || fail=1 test -d unreadable2 && fail=1 -rm -d inacc2 || fail=1 +rm -d inacc2 < /dev/null || fail=1 test -d inacc2 && fail=1 # Test the interactive code paths that are new with 9.2: -mkdir -m0 inacc2 || framework_failure_ +mkdir -m0 inacc3 || framework_failure_ -echo n | rm ---presume-input-tty -di inacc2 > out 2>&1 || fail=1 +echo n | rm ---presume-input-tty -di inacc3 > out 2>&1 || fail=1 # decline: ensure it was not deleted, and the prompt was as expected. -printf "rm: attempt removal of inaccessible directory 'inacc2'? " > exp -test -d inacc2 || fail=1 +printf "rm: attempt removal of inaccessible directory 'inacc3'? " > exp +test -d inacc3 || fail=1 compare exp out || fail=1 -echo y | rm ---presume-input-tty -di inacc2 > out 2>&1 || fail=1 +echo y | rm ---presume-input-tty -di inacc3 > out 2>&1 || fail=1 # accept: ensure it **was** deleted, and the prompt was as expected. -test -d inacc2 && fail=1 +test -d inacc3 && fail=1 compare exp out || fail=1 Exit $fail -- 2.26.2