From: Eric Blake <eblake@redhat.com>
To: cygwin@cygwin.com
Subject: Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules
Date: Thu, 05 Sep 2019 22:46:00 -0000 [thread overview]
Message-ID: <68adcf5e-1e6a-67db-a028-e8953063fbd4@redhat.com> (raw)
In-Reply-To: <MWHPR21MB084583452E7C41D0792C739EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
[-- Attachment #1.1: Type: text/plain, Size: 2610 bytes --]
On 9/5/19 5:01 PM, Stephen Provine via cygwin wrote:
> On 9/5/19 2:05 PM, Eric Blake wrote:
>> On 9/5/19 1:31 PM, Stephen Provine via cygwin wrote:
>>> Not expected.
>
>> Why not? That obeyed cmd's odd rules: The moment you have a " in the
>> command line, that argument continues until end of line or the next "
>> (regardless of how many \ precede the ").
>
> Now I'm really confused. Brian seemed to indicate that the POSIX rules were
> followed, but you're indicating that the Windows command line parsing rules
> are followed. So I assume the reality is that it is actually some mix of the two.
> Is the effective parsing logic implemented by Cygwin documented anywhere?
If you start a Cygwin process from another cygwin process, then only
POSIX rules are in effect. The bash shell parses its command line
according to POSIX rules, creates an argv[] to pass to exec(), then
cygwin1.dll manages to get that argv[], unscathed, to the new child
process (bypassing Window's mechanisms), which uses the argv[] as-is.
If you start a Windows process from a cygwin process, then cygwin1.dll
must quote the arguments into a single concatenated string that will be
reparsed in the manner that the Windows runtime expects, because the
Windows process only gets a single string, not an argv[]. But cygwin
should be providing the correct escaping so that windows then parses it
back into the same intended argv[] (if not, that's a bug in cygwin1.dll).
If you start a cygwin process from Windows, then cygwin1.dll is given
only a single string, which it must parse into argv according to windows
conventions (if it does not produce the same argv[] as a windows process
using CommandLineToArgvW, then that's a bug in cygwin1.dll). But on top
of that, if you are using cmd.exe to generate your command line, then
you must use proper escaping, otherwise, cmd.exe can produce a command
line that has unexpected quoting in the string handed to
CommandLineToArgvW, and the Windows parsing when there are unbalanced
quotes can be screwy (if it encounters a " inside an argument that was
not quoted with ", then that groups remaining text into the same
argument until a balanced " or end of string is encountered). So it is
not always obvious at first glance if what you type in cmd.exe provides
the argv[] that you intended, because of the two layers of
interpretation (one from cmd to Windows, and one from Windows convention
into argv[]).
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-09-05 22:46 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-30 19:31 Stephen Provine via cygwin
2019-08-30 20:53 ` Brian Inglis
2019-08-30 21:21 ` Stephen Provine via cygwin
2019-08-31 4:18 ` Brian Inglis
2019-09-03 16:38 ` Stephen Provine via cygwin
2019-09-04 16:20 ` Brian Inglis
2019-09-04 23:46 ` Stephen Provine via cygwin
2019-09-05 5:29 ` Brian Inglis
2019-09-05 18:31 ` Stephen Provine via cygwin
2019-09-05 19:05 ` Eric Blake
2019-09-05 22:01 ` Stephen Provine via cygwin
2019-09-05 22:46 ` Eric Blake [this message]
2019-09-05 23:45 ` Stephen Provine via cygwin
2019-09-06 0:46 ` Steven Penny
2019-09-06 1:26 ` Eric Blake
2019-09-06 6:20 ` Stephen Provine via cygwin
2019-09-07 21:50 ` Brian Inglis
2019-09-07 12:05 ` Andrey Repin
2019-09-07 12:20 ` Andrey Repin
2019-09-09 16:47 ` Stephen Provine via cygwin
2019-09-09 16:57 ` Stephen Provine via cygwin
2019-09-09 17:11 ` Eric Blake
2019-09-09 19:05 ` Duncan Roe
2019-09-09 19:44 ` Andrey Repin
2019-09-10 12:43 ` Brian Inglis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=68adcf5e-1e6a-67db-a028-e8953063fbd4@redhat.com \
--to=eblake@redhat.com \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).