Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Date: Mon, 20 Nov 2000 14:24:52 -0500 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: [PATCH] Fix for backslash quoting in argument list passing (spawn_guts) Message-ID: <20001120142452.C7398@redhat.com> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: <20001120191155 DOT B78417 AT free DOT bsdshell DOT net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.11i In-Reply-To: <20001120191155.B78417@free.bsdshell.net>; from bogus@bsdshell.net on Mon, Nov 20, 2000 at 07:11:55PM +0100 On Mon, Nov 20, 2000 at 07:11:55PM +0100, Pierre Bogossian wrote: >The argument passing to non-cygwin program doesn't work as expected >in some rare cases. > >Here is an example that demonstrates the problem: > >/tmp $ cat < print_args.c >> #include >> >> int >> main(int argc, char** argv) { >> int i; >> for(i = 1; i < argc; i++) { >> printf("%d: %s\n", i, argv[i]); >> } >> exit(0); >> } >> EOF >/tmp $ gcc -o print_args_cygwin print_args.c >/tmp $ gcc -o print_args_nocygwin -mno-cygwin print_args.c >/tmp $ ./print_args_cygwin.exe '\\" a\' >1: \\" a\ >/tmp $ ./print_args_nocygwin.exe '\\" a\' >1: \\ >2: a" > >As you can see the non-cygwin program gets an inconsistent argv. >The problem comes from spawn_guts and the way it handles blackslash >quoting: > >When the command line is build in spawn_guts, the literal '"' are >preceded by a '\'. But if a litteral '"' is itself preceded by one or >several literal '\', each literal '\' has to be doubled (currently >this is only done for one preceding '\'). If the closing '"' (ie not >literal), is itself preceded by one or several literal '\', those '\' >have to be doubled too (this isn't done at all currently). > >The patch below should fix the problem. >I'm looking forward to you comments, I already submitted a similar >patch 6 months ago but I haven't get any feedback :( I've included what I think is a much simpler patch below. It seems to work correctly using a vc compiled program which echos its args. Sorry for the lack of feedback on your previous patch. I implemented what I thought was the correct fix to your original problem (although I missed this particular problem) but I don't seem to have mentioned that fact in the mailing list. cgf Index: spawn.cc =================================================================== RCS file: /cvs/uberbaum/winsup/cygwin/spawn.cc,v retrieving revision 1.63 diff -u -p -r1.63 spawn.cc --- spawn.cc 2000/11/15 21:04:02 1.63 +++ spawn.cc 2000/11/20 19:24:01 @@ -483,7 +483,12 @@ spawn_guts (HANDLE hToken, const char * for (; (p = strpbrk (a, "\"\\")); a = ++p) { one_line.add (a, p - a); - if ((*p == '\\' && p[1] == '"') || *p == '"') + if (*p == '\\' && p[1] == '\\') + { + one_line.add ("\\\\\\", 3); + p++; + } + else if ((*p == '\\' && p[1] == '"') || *p == '"') one_line.add ("\\", 1); one_line.add (p, 1); } -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com