coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug#1015273: coreutils: rm -d doesn't try to remove unreadable direc


From: George Valkov
Subject: Re: Bug#1015273: coreutils: rm -d doesn't try to remove unreadable directories, lies in error message, with *fails to prompt* with -i
Date: Tue, 28 Feb 2023 13:20:06 +0200

> On 2023-02-26, at 8:35 PM, Pádraig Brady <P@draigBrady.com> wrote:
> 
> On 21/02/2023 12:45, Pádraig Brady wrote:
>> On 21/02/2023 02:59, Jim Meyering wrote:
>>> ---------- Forwarded message ---------
>>> From: Jim Meyering <jim@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: наб <nabijaczleweli@nabijaczleweli.xyz>, <1015273@bugs.debian.org>
>>> Cc: Debian Bug Tracking System <submit@bugs.debian.org>
>>> 
>>> On Mon, Jul 18, 2022 at 12:21 PM наб <nabijaczleweli@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)!

./mkdir -p /tmp/aaa
chmod -r /tmp/aaa

ll /tmp/aaa
total 0
ls: /tmp/aaa: Permission denied

./rm -vid /tmp/aaa ; echo $?
./rm: attempt removal of inaccessible directory '/tmp/aaa'? y
removed directory '/tmp/aaa’
0

uname -a
Darwin gMac.lan 21.6.0 Darwin Kernel Version 21.6.0: Mon Dec 19 20:44:01 PST 
2022; root:xnu-8020.240.18~2/RELEASE_X86_64 x86_64


>>>> 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?

I’m not sure about your environment, but on macOS, if you use Finder to 
navigate to a directory, it might create a hidden file .DS_Store. Then the 
directory is indeed non-empty.


>>>> 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.

Thanks Pádraig!

Yes, this patch fixes the tests. There is no need to press ENTER to kill gdb on 
the latest master. Here are the results:
https://httpstorm.com/share/.openwrt/test/2023-02-06_coreutils-9.1/test-08-0175e337a8bc4f390692d577cb655411bd44d53e-ori.txt

Please let me know when coreutils-9.2 is released!
Cheers mate!

Georgi Valkov
httpstorm.com
nano RTOS




reply via email to

[Prev in Thread] Current Thread [Next in Thread]