RFC: [email protected]

"Tony R. Ambardar" <tonya-1KtHxNhk3+Ww5LPnMra/[email protected]> Fri, 5 Sep 2003 15:51:28 -0700 (PDT)
Newsgroups gmane.comp.gnu.mingw.patches
Message-ID <[email protected]>
Greetings,

(* Note: my environment is fresh MinGW-3.0.0-rc4 + MSYS-1.0.10-rc1 )

I've noticed a serious problem in the way the latest mingw32-make (3.80-3)
handles quoting of arguments passed to sub-shells. Please run the test
Makefile below using "mingw32-make". The correct output should be
"a/\b\c\\\" under your favourite unix but "sed" will error out instead.

Re-run using "make --debug=j -f Makefile.test" and notice in the quoted
argument to "sh.exe -c" that backslashes are not being escaped themselves
by backslashes. So the actual command "sed" sees is 's|\|/|', which
explains the failure.

The attached (minimal) patch to win32/subproc/sub_proc.c attempts to
correct this.  I've rebuilt and tested that it does the right thing, and
it shouldn't affect the MKS, Cygwin or DOS shells either.

I really think the logic of that code section needs to be rewritten, but I
don't have the time to install and test under 3 different environments :(.

Just out of curiosity, are the MinGW changes for Make-3.80 getting folded
back into the GNU sources anytime?

Regards and many thanks to all the MinGW developers,
Tony Ambardar


-------8<--------------8<-- Test Makefile --8<-----------8<-------

# This build rule fails unless the make program correctly
# deals with backslashes in the sub-shell command line.

quote:
	echo 'a\\b\c\\\' | sed -e 's|\\|/|'

-------8<--------------8<-- Test Makefile --8<-----------8<-------
make-mingw-quote.patch (text/plain, 897 B)
--- mingw32-make-3.80.0-3/w32/subproc/sub_proc.c.orig	Sun Aug 31 17:58:42 2003
+++ mingw32-make-3.80.0-3/w32/subproc/sub_proc.c	Mon Sep  1 01:37:46 2003
@@ -978,6 +978,7 @@
 #if !defined(HAVE_MKS_SHELL) && !defined(HAVE_CYGWIN_SHELL)
 			case '\\':
 				backslash_count++;
+				bytes_required += 1;
 				break;
 #endif
 	/*
@@ -1088,6 +1089,11 @@
 #if !defined(HAVE_MKS_SHELL) && !defined(HAVE_CYGWIN_SHELL)
 			} else if (*p == '\\') {
 				backslash_count++;
+
+				while(backslash_count) {
+					*(command_line_i++) = '\\';
+					backslash_count--;
+				}
 			} else {
 				backslash_count = 0;
 #endif
@@ -1105,8 +1111,9 @@
 			 * Add one \ for each \ that precedes the
 			 * closing ".
 			 */
-			while(backslash_count--) {
+			while(backslash_count) {
 				*(command_line_i++) = '\\';
+				backslash_count--;
 			};
 #endif
 			*(command_line_i++) = '\"';