X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=NgisbYKrV6FVIFLE
	UgQpmww/YcrtI1gWPlr5rjLA4Q/gbMHg+Cd+dHGhYSTW2MLaxvXUYiv47d2PDW10
	P7ft+meqHwb1+03ZyR6L6rW41wn4wWUHydnO3RLaZq3judOSh5GeARWEYpzVJaD8
	+Qt8N4AR2b117Ub7y9npFpTP114=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:subject:to:references:from:message-id:date
	:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=GRRYzx9II4h3tHu9qASKkV
	SoT4k=; b=I7/GbK61pkd12KaDut4Ng/FsEsPE4wKecXbOPdgXrHDQTmTsoRlJLy
	SX/WQjLCQc804NffmnmwBZkddUgTiw4FZtaIjvbaAFyGqEzuUJEJvFqSfWXO1Mbc
	4ag9jmy4t/HPLxoAWHRVv5TosSldrPzsFQRI/6gAOCnWiAtUdhcKc=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-6.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=
X-HELO: mx1.redhat.com
Subject: Re: [bug] coreutils: potentially dangerous: $(realpath //) != /
To: cygwin@cygwin.com, cygwin@inbox.ru
References: <20180312232815.692b5da79fc18abf86d42ba1@inbox.ru>
From: Eric Blake <eblake@redhat.com>
Message-ID: <81bda672-dae1-69c8-f12d-990aff3e651f@redhat.com>
Date: Mon, 12 Mar 2018 15:41:00 -0500
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0
MIME-Version: 1.0
In-Reply-To: <20180312232815.692b5da79fc18abf86d42ba1@inbox.ru>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes

On 03/12/2018 03:28 PM, Mikhail Usenko via cygwin wrote:
> coreutils-8.26-2
> cygwin-2.10.0-1
> 
> Test case 1:
> -------------------
> $ realpath //
> //

Correct.

> -------------------
> Expected output: /

Wrong.

On cygwin, '/' and '//' are two different directories, as allowed by 
POSIX. Converting // into / is a violation of the POSIX requirements on 
pathname resolution on systems where // is distinct from /.

> 
> Test case 2:
> -------------------
> $ MYDIR=//
> $ test "$(realpath -e "$MYDIR" )" != /  &&  echo rm -rf "$MYDIR"/*

Wrong.  If you want to guarantee that an arbitrary variable concatenated 
with / and then a glob expands into the expected directory, then YOU 
have to prefilter the arbitrary variable to make sure it does not 
consist solely of slashes.  Or, if you don't want to remove anything 
from the special // directory, you can guarantee that your rm attempt 
will operate on / by supplying more than one slash yourself, as in rm 
-rf "$MYDIR"///* (if MYDIR is empty, that is equivalent to '/*'; if 
MYDIR is non-empty but not //, then you are guaranteed that the * 
expands relative to MYDIR, and only when MYDIR is exactly // do you fail 
to glob what was expected).

At any rate, realpath is not broken, but only your expectations.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

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

