From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 51433 invoked by alias); 6 Sep 2019 01:26:40 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 51425 invoked by uid 89); 6 Sep 2019 01:26:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 06 Sep 2019 01:26:39 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E26A5878E41 for ; Fri, 6 Sep 2019 01:26:37 +0000 (UTC) Received: from [10.3.116.234] (ovpn-116-234.phx2.redhat.com [10.3.116.234]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A80E8600CC for ; Fri, 6 Sep 2019 01:26:37 +0000 (UTC) Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules To: cygwin@cygwin.com References: From: Eric Blake Openpgp: preference=signencrypt Message-ID: Date: Fri, 06 Sep 2019 01:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="43KnC78A6tPT4OgSmbqCwpP1EmPamV5C0" X-IsSubscribed: yes X-SW-Source: 2019-09/txt/msg00051.txt.bz2 --43KnC78A6tPT4OgSmbqCwpP1EmPamV5C0 Content-Type: multipart/mixed; boundary="QbOQnRlfjxp9I2RkiWOxv2ylZLsBghhtN"; protected-headers="v1" From: Eric Blake To: cygwin@cygwin.com Message-ID: Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules References: In-Reply-To: --QbOQnRlfjxp9I2RkiWOxv2ylZLsBghhtN Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Content-length: 1560 On 9/5/19 6:45 PM, Stephen Provine via cygwin wrote: >=20 > To prove it is not going through cmd.exe, I debugged the Go program > to the point that it calls the Win32 CreateProcess function, and the > first two arguments are: >=20 > lpApplicationName: "C:\\cygwin64\\bin\\bash.exe" > lpCommandLine: "C:\\cygwin64\\bin\\bash.exe test.sh foo bar\\\"baz bat" And according to https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/ev= eryone-quotes-command-line-arguments-the-wrong-way/ that is NOT the correct command line to be handing to CreateProcess, at least not if you want things preserved. If I read that page correctly, the unambiguously correct command line should be: "C:\\cygwin64\\bin\\bash.exe test.sh foo \"bar\\\"baz\" bat" >=20 > So unless I'm missing something, bash.exe is not interpreting the command= line > following the rules pointed to by the documentation for CommandLineToArgv= W. Rather, go is not passing the command line to CreateProcess in the way that is unambiguously parseable in the manner expected by CommandLineToArgvW. And because Go is relying on a corner case of ambiguous parsing instead of well-balanced quoting, it's no surprise if cygwin doesn't parse that corner case in the manner expected. A patch to teach cygwin to parse the corner case identically would be welcome, but fixing recipient processes does not scale as well as fixing the culprit source process. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org --QbOQnRlfjxp9I2RkiWOxv2ylZLsBghhtN-- --43KnC78A6tPT4OgSmbqCwpP1EmPamV5C0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-length: 488 -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAl1xtcwACgkQp6FrSiUn Q2q8KAf+KUU8c4xxtPG1mVnjlkCOZZwvJbvS6Hma2TObhx5nI0XvXU8Gh7nSXgbS xHyZ5YjvtDWGI8aNPlgsr6DlzDsf9z/B0ys/X7vb+yVJygdtJFkr4UNqNA4anZYe 1etnXKUj15Wh7/TZBM6DmqvNNN5j8H/abZr6WBywAec1TlpNgtaT8yHbmJKYoc0t if+9baW720WHU3VRSB/cMmHRD3iL+U+AS6v9Kyj5/3Nv+yt8fMluxVjjLVv3q0W2 EP+SwWNvGP8NDRLsmEOPeWI15ZHXVXJkqC4WQEMPURUmxAkzloTz/zBCVnvP58DV DzXj5XVLUsYknWHTnh74BciiawBdZg== =O2or -----END PGP SIGNATURE----- --43KnC78A6tPT4OgSmbqCwpP1EmPamV5C0--