From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailout09.t-online.de (mailout09.t-online.de [194.25.134.84]) by sourceware.org (Postfix) with ESMTPS id 1D5DB38582BE for ; Mon, 8 Aug 2022 11:56:29 +0000 (GMT) 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 Received: from fwd70.dcpf.telekom.de (fwd70.aul.t-online.de [10.223.144.96]) by mailout09.t-online.de (Postfix) with SMTP id BE917A849 for ; Mon, 8 Aug 2022 13:56:27 +0200 (CEST) Received: from [192.168.2.101] ([91.57.241.168]) by fwd70.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1oL1Mx-1UWgIy0; Mon, 8 Aug 2022 13:56:27 +0200 Subject: Re: Deleting a directory with the same name as a shortcut deletes everything in CWD To: cygwin@cygwin.com References: <4b9acea9-b098-2c06-4530-10a4e9ca42b6@oskog97.com> From: Christian Franke 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> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Aug 2022 11:56:30 -0000 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