www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2022/08/08/07:57:50

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1D5DB38582BE
Authentication-Results: sourceware.org;
dmarc=none (p=none dis=none) header.from=t-online.de
Authentication-Results: sourceware.org; spf=none smtp.mailfrom=t-online.de
Subject: Re: Deleting a directory with the same name as a shortcut deletes
everything in CWD
To: cygwin AT cygwin DOT com
References: <4b9acea9-b098-2c06-4530-10a4e9ca42b6 AT oskog97 DOT com>
From: Christian Franke <Christian DOT Franke AT t-online DOT de>
Message-ID: <003884bf-bb7a-984a-668a-21221f142638@t-online.de>
Date: Mon, 8 Aug 2022 13:56:27 +0200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101
SeaMonkey/2.53.12
MIME-Version: 1.0
In-Reply-To: <4b9acea9-b098-2c06-4530-10a4e9ca42b6@oskog97.com>
X-TOI-EXPURGATEID: 150726::1659959787-0144B853-3F81A9BC/0/0 CLEAN NORMAL
X-TOI-MSGID: 50de868f-4b73-461c-b5c8-26802b058e2d
X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, BODY_8BITS,
FREEMAIL_FROM, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A,
RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,
SPF_NONE, TXREP,
T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 278BvVx4015695

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


-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019