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; q=dns; s=default; b=PS2F
	jI/hBSinIj8MVa/cFniyT9Gc2qSU0bHdcaF+6gWnyEpf336BJqjU2IsUkvWW+tni
	CsAt4r03HiG1hD1v95Kp9L43fZIgih78utBLYltgMEuXo4oyTO+2fuC3I7HTKtxc
	7wy9X1CMjId9wQTNNE7jbMcD7UzoYw07lkrGwVQ=
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; s=default; bh=l9ovTwwHwG
	AJwKVrBZwMPGlNIDg=; b=waRGBjtTf0iWXeELW63wzgzh6eJp0QMBJhYBoM171T
	CpflEZOdXqYsANYttwg7tMubIXwFu8/4n8t8t6p/ctd8J6+4mraklFsbWK2OVojH
	JL5fv2cqqY1JE3a3MFkTEw5Jd7lj8XVxBykJx4MeNI4rbZDEhSzrdhFL5aLSBSUW
	o=
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-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
Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules
To: cygwin@cygwin.com
References: <MWHPR21MB08452919F35B1B0C5F0EB4DCB9BD0@MWHPR21MB0845.namprd21.prod.outlook.com> <MWHPR21MB0845F78385792965A94E0CD9B9BD0@MWHPR21MB0845.namprd21.prod.outlook.com> <MWHPR21MB084508155AB621C7AD81309CB9B90@MWHPR21MB0845.namprd21.prod.outlook.com> <MWHPR21MB08456D9F03AF8BD450E6AB2EB9B80@MWHPR21MB0845.namprd21.prod.outlook.com> <MWHPR21MB0845282E7582DC95ADF0F140B9BB0@MWHPR21MB0845.namprd21.prod.outlook.com> <MWHPR21MB084583452E7C41D0792C739EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com> <MWHPR21MB0845845AC5AD54E3A2EAA05EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
From: Eric Blake <eblake@redhat.com>
Openpgp: preference=signencrypt
Message-ID: <c1683718-b696-2fbe-2fc6-2a42103697cf@redhat.com>
Date: Thu, 5 Sep 2019 20:26:36 -0500
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: <MWHPR21MB0845845AC5AD54E3A2EAA05EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="43KnC78A6tPT4OgSmbqCwpP1EmPamV5C0"
X-IsSubscribed: yes

--43KnC78A6tPT4OgSmbqCwpP1EmPamV5C0
Content-Type: multipart/mixed; boundary="QbOQnRlfjxp9I2RkiWOxv2ylZLsBghhtN";
 protected-headers="v1"
From: Eric Blake <eblake@redhat.com>
To: cygwin@cygwin.com
Message-ID: <c1683718-b696-2fbe-2fc6-2a42103697cf@redhat.com>
Subject: Re: Command line processing in dcrt0.cc does not match Microsoft
 parsing rules
References: <MWHPR21MB08452919F35B1B0C5F0EB4DCB9BD0@MWHPR21MB0845.namprd21.prod.outlook.com>
 <MWHPR21MB0845F78385792965A94E0CD9B9BD0@MWHPR21MB0845.namprd21.prod.outlook.com>
 <MWHPR21MB084508155AB621C7AD81309CB9B90@MWHPR21MB0845.namprd21.prod.outlook.com>
 <MWHPR21MB08456D9F03AF8BD450E6AB2EB9B80@MWHPR21MB0845.namprd21.prod.outlook.com>
 <MWHPR21MB0845282E7582DC95ADF0F140B9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
 <MWHPR21MB084583452E7C41D0792C739EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
 <MWHPR21MB0845845AC5AD54E3A2EAA05EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
In-Reply-To: <MWHPR21MB0845845AC5AD54E3A2EAA05EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>


--QbOQnRlfjxp9I2RkiWOxv2ylZLsBghhtN
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable

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"

-----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--
