Deleting a directory with the same name as a shortcut deletes everything in CWD
Christian Franke
Christian.Franke@t-online.de
Mon Aug 8 11:56:27 GMT 2022
Oskar Skog wrote:
> Deleting a directory with the same name as a shortcut deletes everything
> in the current working directory.
>
> Tested on:
> CYGWIN_NT-10.0-19044 3.3.5-341.x86_64 2022-05-13 12:27 UTC x86_64 Cygwin
> CYGWIN_NT-10.0-22000 3.3.5-341.x86_64 2022-05-13 12:27 UTC x86_64 Cygwin
>
> Script to reproduce the bug (also in the tar):
>
> #!/bin/bash
> echo 'EVERY FILE IN THE CURRENT WORKING DIRECTORY WILL BE DELETED!'
> read -p "Enter 'sure' to continue: " var
> echo $var | grep -q sure || exit 1
>
> do_stuff ()
> {
> mkdir foo
> touch Foo.lnk
> if [ -d foo ]; then
> rm -rf foo
> fi
> }
> do_stuff
> do_stuff
> # All files in the current working directory are now GONE!
The first "do_stuff" removes "foo" as expected. The second call
accidentally detects "foo" as a directory because stat("foo", .) returns
"directory" and opendir("foo") succeeds unexpectedly. This behavior
recurses.
Testcase:
$ ls -a
. ..
$ touch link.lnk file.txt
$ ls -a
. .. file.txt link.lnk
$ stat -c %F link.lnk
regular empty file
$ stat -c %F link
directory
$ ls -a link
. .. file.txt link.lnk
$ stat -c %F link/link/link/link
directory
$ ls link/link/link/link
. .. file.txt link.lnk
$ rm link/link/link/link
rm: cannot remove 'link/link/link/link': Is a directory
$ rm -rfv link/link/link/link
removed 'link/link/link/link/file.txt'
removed 'link/link/link/link/link.lnk'
$ ls -a
. ..
--
Regards,
Christian
More information about the Cygwin
mailing list