From: Christian Franke <Christian.Franke@t-online.de>
To: cygwin@cygwin.com
Subject: Re: Deleting a directory with the same name as a shortcut deletes everything in CWD
Date: Mon, 8 Aug 2022 13:56:27 +0200 [thread overview]
Message-ID: <003884bf-bb7a-984a-668a-21221f142638@t-online.de> (raw)
In-Reply-To: <4b9acea9-b098-2c06-4530-10a4e9ca42b6@oskog97.com>
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
next prev parent reply other threads:[~2022-08-08 11:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-08 10:50 Oskar Skog
2022-08-08 11:56 ` Christian Franke [this message]
2022-08-08 23:29 ` Ken Brown
2022-08-09 19:52 ` Ken Brown
2022-08-09 20:01 ` Oskar Skog
2022-08-09 20:11 ` Ken Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=003884bf-bb7a-984a-668a-21221f142638@t-online.de \
--to=christian.franke@t-online.de \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).