This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Command line processing in dcrt0.cc does not match Microsoft parsing rules


On 9/5/19 6:45 PM, Stephen Provine via cygwin wrote:

> 
> 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:
> 
> 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/everyone-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"

> 
> So unless I'm missing something, bash.exe is not interpreting the command line
> following the rules pointed to by the documentation for CommandLineToArgvW.

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.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]