X-Recipient: archive-cygwin AT delorie DOT 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:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=x7gOvl0IBnKvJK8r EKZqi0whGRtSGFMU1BNnRBOpQLbZk7G6Ezj8Y6EZR9IAkYe99S6uUz5SrWf9c0g/ IWoD7Z67XFBccHnFHjO9xO18/Gh+0v3oxv1L7HGr4Z9RerV4BPWD+RtLq2SCJHQH E0A35D2wE/7PiY1oDhElCN+5bpY= 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:reply-to:subject:to:references:from:message-id :date:mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=KAPiasSC8t4r8SWVb3fVAJ AQbP0=; b=VgJn5bDuSJ72YuTqH61m1zUtwQdxpEjMf7sKNoUxF+whn0wIxCgVPg FMyboncYIGirNuBEDemAeUvVS8VpWBpjtU15ewZve5GLO91fsgtF5Yz3Uzdzdv3j ncG3DkLTKxJJJZhdfeSBIpRauPZupEWCSlxgbWiftZKL4HArPSjJQ= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_05,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=disturbing, reacts, calgary, poorly X-HELO: smtp-out-no.shaw.ca Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca Subject: Re: [bug] globify dospath reacts poorly with escaped double quotes To: cygwin AT cygwin DOT com References: From: Brian Inglis Openpgp: preference=signencrypt Message-ID: <915f42e8-7cd1-8fbb-4554-b952503528be@SystematicSw.ab.ca> Date: Tue, 8 Oct 2019 14:09:18 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes On 2019-10-08 03:05, Mingye Wang wrote: > This bug is inherited from early versions of Cygwin. It's so old that > MSYS2 has this problem too. Probably not a bug then but a feature for Cygwin. Msys2 is another system with different goals, using GNU toolchains to build native Windows programs, not a platform for running POSIX applications like Cygwin, and OT for this list. > There is no way of conveying a double quote in an argument once > globify() decides it has seen a dospath. Neither the `\"` nor `""` > work, because they are both unified to `\"` in quoted() and turned > into a `\\` pattern in globify(). Msys2 tools have to make their own arrangements if they support native Windows paths. Personally I found when I used to use DOS and Windows tools, it was easier using slashes instead of backslashes as directory separators, as most interfaces did not care, including most DOS & Windows APIs. > This is problematic for programmers trying to write a routine to > reliably escape an argument for the Cygwin command-line. Backslash escaping and switching enclosing quotes on shell command lines works reliably to pass any arguments into Cygwin programs, as do the various shell command line parameter and wildcard expansions. Passing special characters into arguments interpreted by other programs requires additional care. > A way to patch the problem is with a lookahead in globify(): > > if (dos_spec && *s == '\\') { > /**/p++ = '\\'; > /**/if (s[1] == '"' && s[2]) { > /****/*p = *++s; > /****/continue; > /**/} > } > *p = *s; > > [Apologies for the formatting; the gmail web editor hates leading spaces.] > > (Note: The backslash thing has always been different from the MSCRT > handling, which only transforms backslashes followed by a double > quote. But this is fine as long as we are internally consistent. > Well... is it documented anywhere?) Support of DOS paths is inconsistent in Cygwin utilities and may not work: use cygpath, or the low level API, to convert DOS to POSIX paths before passing to Cygwin programs, or functions. Backslash should only be used to escape command line characters with special meaning to the shell, or escapes in strings in other languages. Any other use should specify what kinds or arguments ypu are trying to handle, how you are getting your arguments in, and passing them to globify. Invoking Cygwin programs from other Cygwin programs is best done using the exec or spawn functions with (unescaped, unquoted) arguments in varargs arg lists or arrays. Invoking Windows programs works best when done from a cmd wrapper, but anything involving any Windows command line requires work to generalize. See previous recent posts for what is required. Avoid system() and similar calls if possible, as they will then go thru an additional shell layer. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. -- 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