GNU bug report logs - #13589
24.2.92; [w32] wrongly escaped call-process of multibyte arguments

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Shigeru Fukaya <shigeru.fukaya@HIDDEN>; dated Wed, 30 Jan 2013 16:38:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Changed bug title to '24.2.92; [w32] wrongly escaped call-process of multibyte arguments' from '24.2.92; wrongly escaped call-process arguments ' Request was from npostavs@HIDDEN to control <at> debbugs.gnu.org. Full text available.

Message received at 13589 <at> debbugs.gnu.org:


Received: (at 13589) by debbugs.gnu.org; 1 Feb 2013 10:14:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Feb 01 05:14:04 2013
Received: from localhost ([127.0.0.1]:58676 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1U1DdE-0004QF-DM
	for submit <at> debbugs.gnu.org; Fri, 01 Feb 2013 05:14:04 -0500
Received: from mtaout23.012.net.il ([80.179.55.175]:52706)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <eliz@HIDDEN>) id 1U1DdB-0004Ph-Cm
	for 13589 <at> debbugs.gnu.org; Fri, 01 Feb 2013 05:14:03 -0500
Received: from conversion-daemon.a-mtaout23.012.net.il by
	a-mtaout23.012.net.il (HyperSendmail v2007.08) id
	<0MHJ00400D7ILR00@HIDDEN> for
	13589 <at> debbugs.gnu.org; Fri, 01 Feb 2013 12:13:11 +0200 (IST)
Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout23.012.net.il
	(HyperSendmail v2007.08) with ESMTPA id
	<0MHJ004XDDPTIR20@HIDDEN>;
	Fri, 01 Feb 2013 12:13:05 +0200 (IST)
Date: Fri, 01 Feb 2013 12:12:57 +0200
From: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#13589: 24.2.92; wrongly escaped call-process arguments
In-reply-to: <B3CE00379EFEA7shigeru.fukaya@HIDDEN>
X-012-Sender: halo1@HIDDEN
To: Shigeru Fukaya <shigeru.fukaya@HIDDEN>
Message-id: <837gmscpg6.fsf@HIDDEN>
References: <B1CDFF07F821D1shigeru.fukaya@HIDDEN> <83wquuh7xz.fsf@HIDDEN>
	<B3CE00379EFEA7shigeru.fukaya@HIDDEN>
X-Spam-Score: 1.5 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
	has
	identified this incoming email as possible spam. The original message
	has been attached to this so you can view it (if it isn't spam) or
	label similar future email.  If you have any questions, see
	the administrator of that system for details.
	Content preview: > From: Shigeru Fukaya <shigeru.fukaya@HIDDEN> >
	Cc: 13589 <at> debbugs.gnu.org > Date: Fri,
	01 Feb 2013 13:50:13 +0900 > > Why I used CharNextExA is I can't
	find such functions for encoded > strings in Emacs. [...] 
	Content analysis details:   (1.5 points, 10.0 required)
	pts rule name              description
	---- ----------------------
	--------------------------------------------------
	-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/,
	no trust [80.179.55.175 listed in list.dnswl.org]
	0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail)
	0.8 BAYES_50               BODY: Bayes spam probability is 40 to 60%
	[score: 0.4808]
X-Debbugs-Envelope-To: 13589
Cc: 13589 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.13
Precedence: list
Reply-To: Eli Zaretskii <eliz@HIDDEN>
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: 0.2 (/)

> From: Shigeru Fukaya <shigeru.fukaya@HIDDEN>
> Cc: 13589 <at> debbugs.gnu.org
> Date: Fri, 01 Feb 2013 13:50:13 +0900
> 
> Why I used CharNextExA is I can't find such functions for encoded
> strings in Emacs.

There aren't any, except when the strings are encoded in UTF-8.

> Possible alternative is to change the quoting
> process out of binary to elisp code.  Or provide some hook for it?

We cannot move this to Lisp, I think, because C code calls
Fcall_process directly from C.

I think the right place for this processing is in Fcall_process,
around line 425 of callproc.c, where we encode the command-line
arguments and stuff them into new_argv[] array, to be passed to
child_setup.  Each argument should be quoted _before_ it is encoded,
e.g., by running it through a w32-specific function.  Since the Emacs
internal representation of characters is based on UTF-8, the problem
with backslashes incorrectly interpreted cannot happen if we do this
processing before encoding the result.  We can then remove most of the
code in sys_spawnve that quotes special characters, except for quoting
argv[0] if it includes whitespace.

> And, anyway, could you please initialize 'escape_char'

Done in revision 111212 on the emacs-24 branch.

> so that we can safely set `w32-quote-process-args' to nil and do
> some quoting by ourselves (using advise or something).

Note that, even if w32-quote-process-args is nil, the current code in
sys_spawnve can still quote some parts of the command arguments, e.g.,
if an argument is empty.  So initializing escape_char to zero is not
TRT, IMO; I initialized it to '\' instead.

Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#13589; Package emacs,w32. Full text available.

Message received at 13589 <at> debbugs.gnu.org:


Received: (at 13589) by debbugs.gnu.org; 1 Feb 2013 04:51:06 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jan 31 23:51:06 2013
Received: from localhost ([127.0.0.1]:58410 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1U18ag-0005TS-7j
	for submit <at> debbugs.gnu.org; Thu, 31 Jan 2013 23:51:06 -0500
Received: from mail-da0-f51.google.com ([209.85.210.51]:38195)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <shigeru.fukaya@HIDDEN>) id 1U18ad-0005TK-MD
	for 13589 <at> debbugs.gnu.org; Thu, 31 Jan 2013 23:51:04 -0500
Received: by mail-da0-f51.google.com with SMTP id i30so1579941dad.24
	for <13589 <at> debbugs.gnu.org>; Thu, 31 Jan 2013 20:50:16 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=x-received:from:to:cc:subject:date:mime-version:content-type
	:content-transfer-encoding:x-mailer:in-reply-to:references
	:message-id; bh=gm1PWAe5h29763TIbsclrmNFrx+ihV1aIJ+tLY6Ww8A=;
	b=PY04sMv0pW7uuFjeE7vm0p/5VXf5lx5RUV9lL5HzLy1yo17xjYqiAVPP8bsQOnMFPT
	AwBG6DzaD0+s/o0DwnjUxSD9TznmXDG+irlR1AtOwSxs4RPtF10c1AF6LL2HhuZJysLu
	fxO2sdSc1ad4MJ0wNCmsGUJ1vSW4w5EEfhPBxX2afblXCaYxF7SULNamVMCaTT/zSF+O
	Gp7JS+StzQA027QejWzHT+m2kXLhGnGVFc8G9OD8Fb52qAIju/8BDew1y5HykIyxb5Cw
	1sZBFfKjHX5TdfYFb3yr8E4hjiUatmIraojRq6q21wirskTTyEv01++GdFL19MygcOsW
	2zxQ==
X-Received: by 10.68.219.67 with SMTP id pm3mr28712767pbc.150.1359694216694;
	Thu, 31 Jan 2013 20:50:16 -0800 (PST)
Received: from gmail.com (115x125x38x6.ap115.ftth.ucom.ne.jp. [115.125.38.6])
	by mx.google.com with ESMTPS id
	gj1sm7170264pbc.11.2013.01.31.20.50.13
	(version=TLSv1 cipher=RC4-SHA bits=128/128);
	Thu, 31 Jan 2013 20:50:15 -0800 (PST)
From: Shigeru Fukaya <shigeru.fukaya@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#13589: 24.2.92; wrongly escaped call-process arguments
Date: Fri, 01 Feb 2013 13:50:13 +0900
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
X-Mailer: HidemaruMail 6.00 (WinNT,601)
In-Reply-To: <83wquuh7xz.fsf@HIDDEN>
References: <B1CDFF07F821D1shigeru.fukaya@HIDDEN> <83wquuh7xz.fsf@HIDDEN>
Message-Id: <B3CE00379EFEA7shigeru.fukaya@HIDDEN>
X-Spam-Score: 0.1 (/)
X-Debbugs-Envelope-To: 13589
Cc: 13589 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.13
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -2.6 (--)

Thank you for your reply.

Why I used CharNextExA is I can't find such functions for encoded
strings in Emacs.  Possible alternative is to change the quoting
process out of binary to elisp code.  Or provide some hook for it?

And, anyway, could you please initialize 'escape_char', so that we can
safely set `w32-quote-process-args' to nil and do some quoting by
ourselves (using advise or something).

Shigeru

>> From: Shigeru Fukaya <shigeru.fukaya@HIDDEN>
>> Date: Thu, 31 Jan 2013 01:36:35 +0900
>> 
>> `call-process' wrongly treats those multibyte characters whose
>> 2nd byte is 0x5c.
>> It is bacause sys_spawnve in w32proc.c does bad quoting process.
>> 
>> Bad example:
>> 
>> (let ((coding-system-for-write 'cp932))
>>   (call-process "sh" nil t nil "-c" "ls d:/tmp/表*"))
>> ls: cannot access d:/tmp/表*: No such file or directory
>> 2
>> 
>> Correct example:
>> 
>> (let ((coding-system-for-write 'cp932))
>>   (call-process "sh" nil t nil "-c" "ls d:/tmp/表*"))
>> d:/tmp/表
>> d:/tmp/表1
>> 
>> d:/tmp/表表:
>> abc
>> 0
>> 
>> I tried fixing it (after w32.c as a reference).
>> Additionally, I set uninitialized `escape_char' to 0.
>
>Thanks for the report and the patch.
>
>Unfortunately, I don't think the solution you suggest is the right
>one.  It is one thing to support only Windows codepages in encoding of
>file names, as w32.c does: after all, that's the limitation of the OS
>APIs we use.  But imposing the same limitation for encoding
>command-line arguments to subprocesses is something entirely
>different.  E.g., consider such trivial example as invoking a speller:
>the encoding used to pass non-ASCII characters on the command line in
>this case might have nothing at all to do with Windows codepages.  We
>can no longer justify not supporting shift_jis in this case, for
>example.  IOW, using CharNextExA here would impose an unreasonably bad
>restriction on how subprocesses can be invoked from Emacs.
>
>In addition, without also fixing cmdproxy, which does similar things,
>this is not going to solve the problem, except in a few select cases.
>E.g., I think it's enough for you to use shell-file-name instead of
>"sh" to have the command be handed to cmdproxy by default, and then
>you'll have the same problem there.
>
>We need a better, less restricted and more thorough solution.  I don't
>yet know which one.
>
>Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#13589; Package emacs,w32. Full text available.

Message received at 13589 <at> debbugs.gnu.org:


Received: (at 13589) by debbugs.gnu.org; 30 Jan 2013 17:57:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 30 12:57:01 2013
Received: from localhost ([127.0.0.1]:56042 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1U0bu8-00059W-EG
	for submit <at> debbugs.gnu.org; Wed, 30 Jan 2013 12:57:00 -0500
Received: from mtaout23.012.net.il ([80.179.55.175]:43437)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <eliz@HIDDEN>) id 1U0bu5-00059N-GM
	for 13589 <at> debbugs.gnu.org; Wed, 30 Jan 2013 12:56:58 -0500
Received: from conversion-daemon.a-mtaout23.012.net.il by
	a-mtaout23.012.net.il (HyperSendmail v2007.08) id
	<0MHG00D009OZIX00@HIDDEN> for
	13589 <at> debbugs.gnu.org; Wed, 30 Jan 2013 19:55:33 +0200 (IST)
Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout23.012.net.il
	(HyperSendmail v2007.08) with ESMTPA id
	<0MHG00D7S9SLEW60@HIDDEN>;
	Wed, 30 Jan 2013 19:55:33 +0200 (IST)
Date: Wed, 30 Jan 2013 19:55:20 +0200
From: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#13589: 24.2.92; wrongly escaped call-process arguments
In-reply-to: <B1CDFF07F821D1shigeru.fukaya@HIDDEN>
X-012-Sender: halo1@HIDDEN
To: Shigeru Fukaya <shigeru.fukaya@HIDDEN>
Message-id: <83wquuh7xz.fsf@HIDDEN>
MIME-version: 1.0
Content-type: text/plain; charset=iso-2022-jp
Content-transfer-encoding: 8bit
References: <B1CDFF07F821D1shigeru.fukaya@HIDDEN>
X-Spam-Score: 1.5 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
	has
	identified this incoming email as possible spam. The original message
	has been attached to this so you can view it (if it isn't spam) or
	label similar future email.  If you have any questions, see
	the administrator of that system for details.
	Content preview: > From: Shigeru Fukaya <shigeru.fukaya@HIDDEN> >
	Date: Thu,
	31 Jan 2013 01:36:35 +0900 > > `call-process' wrongly treats those
	multibyte
	characters whose > 2nd byte is 0x5c. > It is bacause sys_spawnve in
	w32proc.c does bad quoting process. > > Bad example: > > (let
	((coding-system-for-write
	'cp932)) > (call-process "sh" nil t nil "-c" "ls d:/tmp/表*")) >
	ls:
	cannot access d:/tmp/表*: No such file or directory > 2 > >
	Correct
	example: > > (let ((coding-system-for-write 'cp932)) > (call-process
	"sh" nil t nil "-c" "ls d:/tmp/表*")) > d:/tmp/表 >
	d:/tmp/表1
	> > d:/tmp/表表: > abc > 0 > > I tried fixing it (after w32.c as
	a reference). > Additionally,
	I set uninitialized `escape_char' to 0. [...] 
	Content analysis details:   (1.5 points, 10.0 required)
	pts rule name              description
	---- ----------------------
	--------------------------------------------------
	-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/,
	no trust [80.179.55.175 listed in list.dnswl.org]
	0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail)
	0.8 BAYES_50               BODY: Bayes spam probability is 40 to 60%
	[score: 0.4861]
X-Debbugs-Envelope-To: 13589
Cc: 13589 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.13
Precedence: list
Reply-To: Eli Zaretskii <eliz@HIDDEN>
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: 0.7 (/)

> From: Shigeru Fukaya <shigeru.fukaya@HIDDEN>
> Date: Thu, 31 Jan 2013 01:36:35 +0900
> 
> `call-process' wrongly treats those multibyte characters whose
> 2nd byte is 0x5c.
> It is bacause sys_spawnve in w32proc.c does bad quoting process.
> 
> Bad example:
> 
> (let ((coding-system-for-write 'cp932))
>   (call-process "sh" nil t nil "-c" "ls d:/tmp/表*"))
> ls: cannot access d:/tmp/表*: No such file or directory
> 2
> 
> Correct example:
> 
> (let ((coding-system-for-write 'cp932))
>   (call-process "sh" nil t nil "-c" "ls d:/tmp/表*"))
> d:/tmp/表
> d:/tmp/表1
> 
> d:/tmp/表表:
> abc
> 0
> 
> I tried fixing it (after w32.c as a reference).
> Additionally, I set uninitialized `escape_char' to 0.

Thanks for the report and the patch.

Unfortunately, I don't think the solution you suggest is the right
one.  It is one thing to support only Windows codepages in encoding of
file names, as w32.c does: after all, that's the limitation of the OS
APIs we use.  But imposing the same limitation for encoding
command-line arguments to subprocesses is something entirely
different.  E.g., consider such trivial example as invoking a speller:
the encoding used to pass non-ASCII characters on the command line in
this case might have nothing at all to do with Windows codepages.  We
can no longer justify not supporting shift_jis in this case, for
example.  IOW, using CharNextExA here would impose an unreasonably bad
restriction on how subprocesses can be invoked from Emacs.

In addition, without also fixing cmdproxy, which does similar things,
this is not going to solve the problem, except in a few select cases.
E.g., I think it's enough for you to use shell-file-name instead of
"sh" to have the command be handed to cmdproxy by default, and then
you'll have the same problem there.

We need a better, less restricted and more thorough solution.  I don't
yet know which one.

Thanks.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#13589; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 30 Jan 2013 16:37:41 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 30 11:37:41 2013
Received: from localhost ([127.0.0.1]:55938 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1U0afM-0000yU-HL
	for submit <at> debbugs.gnu.org; Wed, 30 Jan 2013 11:37:41 -0500
Received: from eggs.gnu.org ([208.118.235.92]:47791)
	by debbugs.gnu.org with esmtp (Exim 4.72)
	(envelope-from <shigeru.fukaya@HIDDEN>) id 1U0afJ-0000yM-HL
	for submit <at> debbugs.gnu.org; Wed, 30 Jan 2013 11:37:39 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <shigeru.fukaya@HIDDEN>) id 1U0aeb-0002MS-F7
	for submit <at> debbugs.gnu.org; Wed, 30 Jan 2013 11:36:59 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	RCVD_IN_DNSWL_LOW,T_DKIM_INVALID autolearn=unavailable version=3.3.2
Received: from lists.gnu.org ([208.118.235.17]:58682)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <shigeru.fukaya@HIDDEN>) id 1U0aeb-0002ML-B5
	for submit <at> debbugs.gnu.org; Wed, 30 Jan 2013 11:36:53 -0500
Received: from eggs.gnu.org ([208.118.235.92]:59061)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <shigeru.fukaya@HIDDEN>) id 1U0aeW-0005H1-Lb
	for bug-gnu-emacs@HIDDEN; Wed, 30 Jan 2013 11:36:53 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <shigeru.fukaya@HIDDEN>) id 1U0aeP-0002It-KR
	for bug-gnu-emacs@HIDDEN; Wed, 30 Jan 2013 11:36:48 -0500
Received: from mail-pa0-f47.google.com ([209.85.220.47]:40812)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <shigeru.fukaya@HIDDEN>) id 1U0aeP-0002If-Av
	for bug-gnu-emacs@HIDDEN; Wed, 30 Jan 2013 11:36:41 -0500
Received: by mail-pa0-f47.google.com with SMTP id bj3so22911pad.34
	for <bug-gnu-emacs@HIDDEN>; Wed, 30 Jan 2013 08:36:40 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=x-received:from:to:subject:date:mime-version:content-type
	:content-transfer-encoding:x-mailer:message-id;
	bh=X3HWCHhevMd4KFpHOfqS5pDyYK8eWN1zx6T2VbMTt68=;
	b=0zdMQ3xukYOCVq0E+2go47++I4g9mqwZsuRJkI1Uvkf1lyLasfPMUGwpDTNWWv3MHN
	wf4zdnKsQu3vhw4tCxkIM1sWNpcWfCMGvbgg7MI6xG6r0FwubWJLWrPsy9LKmqTVNjVv
	YhaJ/7CIXLpDguIRxjnj0UYTarlRPIZ6Gf0oFy7egpdeiiieUJDza1ZEYl28z1hyMLEn
	mfZL3t4kFX0NvOfkYII0/F1V2LqXz+LLzEoUixi5xFPHMgDyMmstVSLdH3qIjHUtaHqZ
	FaYpn0iCbhipS2oqDYlPargRk3orWCcUXq8RmcKW801sXPJUky75nnGJBwJ6NBbclp8i
	Qpqw==
X-Received: by 10.66.81.199 with SMTP id c7mr12652482pay.39.1359563800035;
	Wed, 30 Jan 2013 08:36:40 -0800 (PST)
Received: from gmail.com (115x125x38x6.ap115.ftth.ucom.ne.jp. [115.125.38.6])
	by mx.google.com with ESMTPS id
	sb3sm2030686pbc.44.2013.01.30.08.36.36
	(version=TLSv1 cipher=RC4-SHA bits=128/128);
	Wed, 30 Jan 2013 08:36:38 -0800 (PST)
From: Shigeru Fukaya <shigeru.fukaya@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 24.2.92; wrongly escaped call-process arguments 
Date: Thu, 31 Jan 2013 01:36:35 +0900
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit
X-Mailer: HidemaruMail 6.00 (WinNT,601)
Message-Id: <B1CDFF07F821D1shigeru.fukaya@HIDDEN>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.17
X-Spam-Score: -3.4 (---)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.13
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <http://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <http://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <http://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
	<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Sender: debbugs-submit-bounces <at> debbugs.gnu.org
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
X-Spam-Score: -6.1 (------)

Hi,

`call-process' wrongly treats those multibyte characters whose
2nd byte is 0x5c.
It is bacause sys_spawnve in w32proc.c does bad quoting process.

Bad example:

(let ((coding-system-for-write 'cp932))
  (call-process "sh" nil t nil "-c" "ls d:/tmp/表*"))
ls: cannot access d:/tmp/表*: No such file or directory
2

Correct example:

(let ((coding-system-for-write 'cp932))
  (call-process "sh" nil t nil "-c" "ls d:/tmp/表*"))
d:/tmp/表
d:/tmp/表1

d:/tmp/表表:
abc
0

I tried fixing it (after w32.c as a reference).
Additionally, I set uninitialized `escape_char' to 0.

Note that coding of command lines is different from coding of process inputs.

Regards,
Shigeru


*** w32proc.c	Thu Jan 31 01:06:10 2013
--- w32proc.old.c	Sun Jan 27 11:32:55 2013
***************
*** 1419,1488 ****
    *nptr = NULL;
  }
  
- 
- /* Code copied from max_filename_mbslen in w32.c */
- 
- /* Current codepage for encoding command lines.  */
- static int command_line_codepage;
- 
- /* Return the maximum length in bytes of a multibyte character
-    sequence encoded in the current ANSI codepage.  This is required to
-    correctly walk the encoded file names one character at a time.  */
- static int
- max_cmdline_mbslen (void)
- {
-   /* A simple cache to avoid calling GetCPInfo every time we need to
-      normalize a file name.  The file-name encoding is not supposed to
-      be changed too frequently, if ever.  */
-   static Lisp_Object last_cmdline_encoding;
-   static int last_max_mbslen;
-   Lisp_Object current_encoding;
- 
-   current_encoding = Vcoding_system_for_write;
- 
-   if (!EQ (last_cmdline_encoding, current_encoding))
-     {
-       CPINFO cp_info;
- 
-       last_cmdline_encoding = current_encoding;
-       /* Default to the current ANSI codepage.  */
-       command_line_codepage = w32_ansi_code_page;
-       if (!NILP (current_encoding))
- 	{
- 	  char *cpname = SDATA (SYMBOL_NAME (current_encoding));
- 	  char *cp = NULL, *end;
- 	  int cpnum;
- 
- 	  if (strncmp (cpname, "cp", 2) == 0)
- 	    cp = cpname + 2;
- 	  else if (strncmp (cpname, "windows-", 8) == 0)
- 	    cp = cpname + 8;
- 
- 	  if (cp)
- 	    {
- 	      end = cp;
- 	      cpnum = strtol (cp, &end, 10);
- 	      if (cpnum && *end == '\0' && end - cp >= 2)
- 		command_line_codepage = cpnum;
- 	    }
- 	}
- 
-       if (!command_line_codepage)
- 	command_line_codepage = CP_ACP; /* CP_ACP = 0, but let's not assume that */
- 
-       if (!GetCPInfo (command_line_codepage, &cp_info))
- 	{
- 	  command_line_codepage = CP_ACP;
- 	  if (!GetCPInfo (command_line_codepage, &cp_info))
- 	    emacs_abort ();
- 	}
-       last_max_mbslen = cp_info.MaxCharSize;
-     }
- 
-   return last_max_mbslen;
- }
- 
- 
  /* When a new child process is created we need to register it in our list,
     so intercept spawn requests.  */
  int
--- 1419,1424 ----
***************
*** 1495,1501 ****
    child_process *cp;
    int is_dos_app, is_cygnus_app, is_gui_app;
    int do_quoting = 0;
!   char escape_char = 0;
    /* We pass our process ID to our children by setting up an environment
       variable in their environment.  */
    char ppid_env_var_buffer[64];
--- 1431,1437 ----
    child_process *cp;
    int is_dos_app, is_cygnus_app, is_gui_app;
    int do_quoting = 0;
!   char escape_char;
    /* We pass our process ID to our children by setting up an environment
       variable in their environment.  */
    char ppid_env_var_buffer[64];
***************
*** 1508,1514 ****
       Some extra whitespace characters need quoting in Cygwin programs,
       so this list is conditionally modified below.  */
    char *sepchars = " \t*?";
-   int dbcs_p = max_cmdline_mbslen () > 1;
  
    /* We don't care about the other modes */
    if (mode != _P_NOWAIT)
--- 1444,1449 ----
***************
*** 1622,1628 ****
  
        if (*p == 0)
  	need_quotes = 1;
!       for ( ; *p; p = !dbcs_p ? p + 1 : CharNextExA (command_line_codepage, p, 0))
  	{
  	  if (escape_char == '"' && *p == '\\')
  	    /* If it's a Cygwin app, \ needs to be escaped.  */
--- 1557,1563 ----
  
        if (*p == 0)
  	need_quotes = 1;
!       for ( ; *p; p++)
  	{
  	  if (escape_char == '"' && *p == '\\')
  	    /* If it's a Cygwin app, \ needs to be escaped.  */
***************
*** 1674,1680 ****
  
        if (do_quoting)
  	{
! 	  for ( ; *p; p = !dbcs_p ? p + 1 : CharNextExA (command_line_codepage, p, 0))
  	    if ((strchr (sepchars, *p) != NULL) || *p == '"')
  	      need_quotes = 1;
  	}
--- 1609,1615 ----
  
        if (do_quoting)
  	{
! 	  for ( ; *p; p++)
  	    if ((strchr (sepchars, *p) != NULL) || *p == '"')
  	      need_quotes = 1;
  	}
***************
*** 1702,1708 ****
  	      *parg++ = *p++;
  	    }
  #else
! 	  while (*p)
  	    {
  	      if (*p == '"')
  		{
--- 1637,1643 ----
  	      *parg++ = *p++;
  	    }
  #else
! 	  for ( ; *p; p++)
  	    {
  	      if (*p == '"')
  		{
***************
*** 1717,1736 ****
  		}
  	      else if (escape_char == '"' && *p == '\\')
  		*parg++ = '\\';
  
  	      if (*p == escape_char && escape_char != '"')
  		escape_char_run++;
  	      else
  		escape_char_run = 0;
- 	      if (!dbcs_p)
- 		*parg++ = *p++;
- 	      else
- 		{
- 		  char *p1 = CharNextExA (command_line_codepage, p, 0);
- 
- 		  while (p < p1)
- 		    *parg++ = *p++;
- 		}
  	    }
  	  /* double escape chars before enclosing quote */
  	  while (escape_char_run > 0)
--- 1652,1663 ----
  		}
  	      else if (escape_char == '"' && *p == '\\')
  		*parg++ = '\\';
+ 	      *parg++ = *p;
  
  	      if (*p == escape_char && escape_char != '"')
  		escape_char_run++;
  	      else
  		escape_char_run = 0;
  	    }
  	  /* double escape chars before enclosing quote */
  	  while (escape_char_run > 0)




Acknowledgement sent to Shigeru Fukaya <shigeru.fukaya@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#13589; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 25 Mar 2017 04:15:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.