This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: [bug] coreutils: potentially dangerous: $(realpath //) != /
- From: Eric Blake <eblake at redhat dot com>
- To: cygwin at cygwin dot com, cygwin at inbox dot ru
- Date: Mon, 12 Mar 2018 15:41:00 -0500
- Subject: Re: [bug] coreutils: potentially dangerous: $(realpath //) != /
- Authentication-results: sourceware.org; auth=none
- References: <20180312232815.692b5da79fc18abf86d42ba1@inbox.ru>
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