delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/09/05/19:46:41

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:from:reply-to:to:subject:date:message-id
:references:in-reply-to:content-type:content-transfer-encoding
:mime-version; q=dns; s=default; b=Ht27P/mneQ+JyI7eLRw5v6SHIjMET
9/+ouR148SRgsHS1IByKaMiO4CAqVpyY6jHE18gua+xRKa/tetdJOK1NhQXnZT3q
O/he5oL6BNQYPXtuEbzrFxjTa9NqyyPh6Kz06OAvSxcAEUaAV16U3m7efo+KUcAZ
s0dHqOLZ1kzi3o=
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:from:reply-to:to:subject:date:message-id
:references:in-reply-to:content-type:content-transfer-encoding
:mime-version; s=default; bh=0IX6zofpOCJrquXjHZP4fD1Y/q0=; b=Eyf
oA2zGTFfrx5lpQKBLkYJSEAy+iA1yDH+bhuMmsYxV9MFgor9R5/ZH2PKrgBSQx4G
gayLtHagB5KZMEX1MOw9I5QCEv+2dJDU7HAABHaLF4+rI6dPZEyFssTkGNkl/O0G
vHOwSPY74SP3fGYs0bp9HMnNon094x4uQd8qoQ2U=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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=-0.9 required=5.0 tests=BAYES_00,FORGED_SPF_HELO,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=no version=3.3.1 spammy=reproduces
X-HELO: NAM01-SN1-obe.outbound.protection.outlook.com
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RRMQoFUjcJavpYFbEC8vmsRUZy4+zSIsFGL1SOBxO/piKvnym3w6NKW/iw94QNRQ3qtXB6+EpNlel0xHYhAMAA1JAO0XCwH2Qj7dGMeDoR+znS7txIImxZeDXA/4UEB3BwGbIpytcNCGKTWXYBuZ5Ivs2jGwJ/0wUci/Nmld+VRbbGsBnXeIG7pxHskZkSGF7XFmpMm3x11WqHFUGosbPpJWXqS4AtRhZPQaooZbI5FE6+s5dRL1WnAEaF+ZUT+3B0ayAFahzInUupYEbaXLydQ67BPtpFDXkEIk1AnWHqmtzIEtA/S2Sw65F6NfgwJm2V9eOzKvwjmNBMKsDPm2iQ==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EqNj0WYSOM1w6V6rig/xKUm2Xc0gM+xHPcBw0wpmZ60=; b=WnzsID5upW2z7i8l/lGO3huY2Dkb87AfphaqLbQZ+ZkhBDbBSndUUwFw3X/FYQrZ1HCwchpSU5TPuCRhSsBLQMgws6z7t7rqGR++w+76/oZmr9m49ts6FvZhB38uHGEdH7Axq3zw3rD8DAhveu3oUNXEWDTnkZI0KX2YPEEMIKgzMY2JFQy1MvVtJ7BLzdLuDvJRqci29ccKtsvjw/eTYY5FQyF+xgDlMXALRBKOCYrWdfgcUDPdgsvf63/r2NTqqhSUSQBanu1I4VEOSMs6t7HU8kRmIPRDdpZNuI6usaW72qgZa4hlfTL1GQLtwONQRTQLu2YSUAemKf2gp8DwCg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EqNj0WYSOM1w6V6rig/xKUm2Xc0gM+xHPcBw0wpmZ60=; b=I4C/Z0E8tHaBzRA1vdN/XwQJHHhCON9nAMfRgdxOXBxwzbd+oZmpKwdaD1adXhCN27wPoEeET75MV0bu3vH0txswCfN2uisEMuUKTImDn0xACXvguV/Sf5U1T9ZgsofjYqyiTg5M4V9pDZodrGAhpkF0I2GLlVh3hyJgALmiWCc=
From: "Stephen Provine via cygwin" <cygwin AT cygwin DOT com>
Reply-To: Stephen Provine <stephpr AT microsoft DOT com>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: RE: Command line processing in dcrt0.cc does not match Microsoft parsing rules
Date: Thu, 5 Sep 2019 23:45:44 +0000
Message-ID: <MWHPR21MB0845845AC5AD54E3A2EAA05EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
References: <MWHPR21MB08452919F35B1B0C5F0EB4DCB9BD0 AT MWHPR21MB0845 DOT namprd21 DOT prod DOT outlook DOT com> <MWHPR21MB0845F78385792965A94E0CD9B9BD0 AT MWHPR21MB0845 DOT namprd21 DOT prod DOT outlook DOT com> <MWHPR21MB084508155AB621C7AD81309CB9B90 AT MWHPR21MB0845 DOT namprd21 DOT prod DOT outlook DOT com> <MWHPR21MB08456D9F03AF8BD450E6AB2EB9B80 AT MWHPR21MB0845 DOT namprd21 DOT prod DOT outlook DOT com> <MWHPR21MB0845282E7582DC95ADF0F140B9BB0 AT MWHPR21MB0845 DOT namprd21 DOT prod DOT outlook DOT com> <MWHPR21MB084583452E7C41D0792C739EB9BB0 AT MWHPR21MB0845 DOT namprd21 DOT prod DOT outlook DOT com>
In-Reply-To: <MWHPR21MB084583452E7C41D0792C739EB9BB0@MWHPR21MB0845.namprd21.prod.outlook.com>
authentication-results: spf=none (sender IP is ) smtp.mailfrom=stephpr AT microsoft DOT com;
x-ms-oob-tlc-oobclassifiers: OLM:9508;
received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts)
x-ms-exchange-senderadcheck: 1
x-ms-exchange-transport-forked: True
MIME-Version: 1.0
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: tqbRAuEkEEOLiqJgDjvfPLARh27pLdnQBwhVBuqzCoNhjZmWo7p2bgWfnUTYfnZx6mdW4AWp3hXq9QvbNqtjdg==
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id x85NkM3u027959

On 9/5/19 5:46 PM, Eric Blake wrote:
> 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

Great explanation, it's very helpful.

I've been using cmd.exe to generate the command line for my tests, but the
original problem was when my compiled Go binary directly executes another
Windows process using the Win32 APIs like CreateProcess directly. Here's a
simple Go program that reproduces the issue:

package main

import (
	"log"
	"os"
	"os/exec"
)

func main() {
	cmd := exec.Command("C:\\cygwin64\\bin\\bash.exe", "test.sh", "foo", "bar\"baz", "bat")
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}
}

The output of this process is:

foo
bar\baz bat


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"

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

Thanks,
Stephen

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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019