This is the mail archive of the cygwin@sources.redhat.com 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]

Re: [PATCH] Fix for backslash quoting in argument list passing (spawn_guts)


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 <<EOF > print_args.c
>> #include <stdio.h>
>>
>> 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@sourceware.cygnus.com


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