Skip to content
Browse files

Fix on Windows the open-process procedure which was not escaping the …

…command line arguments properly. This was causing shell-command to fail also, bug #152.
  • Loading branch information...
1 parent 8ccd2bd commit 747c3e304618827fe514414b1ea2e696645c5b76 @feeley committed Jan 26, 2012
Showing with 155 additions and 88 deletions.
  1. +78 −26 bin/gambc-cc.bat.windows.in
  2. +2 −2 include/stamp.h
  3. +75 −60 lib/os_io.c
View
104 bin/gambc-cc.bat.windows.in
@@ -28,7 +28,9 @@ set GAMBCGSILIB=@GAMBCGSILIB_BAT@
set LIB_PREFIX=@LIB_PREFIX_BAT@
set LIB_EXTENSION=@LIB_EXTENSION_BAT@
-if not "%1" == "obj" goto not_obj
+if "%1" == "obj" goto obj
+if not "%1" == ""obj"" goto not_obj
+:obj
if not "%GAMBC_CC_VERBOSE%" == "yes" goto not_obj_verbose
echo.@BUILD_OBJ_ECHO_BAT@
@@ -39,7 +41,9 @@ echo.@BUILD_OBJ_ECHO_BAT@
goto end
:not_obj
-if not "%1" == "dyn" goto not_dyn
+if "%1" == "dyn" goto dyn
+if not "%1" == ""dyn"" goto not_dyn
+:dyn
if not "%GAMBC_CC_VERBOSE%" == "yes" goto not_dyn_verbose
echo.@BUILD_DYN_ECHO_BAT@
@@ -50,7 +54,9 @@ echo.@BUILD_DYN_ECHO_BAT@
goto end
:not_dyn
-if not "%1" == "lib" goto not_lib
+if "%1" == "lib" goto lib
+if not "%1" == ""lib"" goto not_lib
+:lib
if not "%GAMBC_CC_VERBOSE%" == "yes" goto not_lib_verbose
echo.@BUILD_LIB_ECHO_BAT@
@@ -61,7 +67,9 @@ echo.@BUILD_LIB_ECHO_BAT@
goto end
:not_lib
-if not "%1" == "exe" goto not_exe
+if "%1" == "exe" goto exe
+if not "%1" == ""exe"" goto not_exe
+:exe
if not "%GAMBC_CC_VERBOSE%" == "yes" goto not_exe_verbose
echo.@BUILD_EXE_ECHO_BAT@
@@ -72,112 +80,156 @@ echo.@BUILD_EXE_ECHO_BAT@
goto end
:not_exe
-if not "%1" == "C_COMPILER" goto not_C_COMPILER
+if "%1" == "C_COMPILER" goto C_COMPILER
+if not "%1" == ""C_COMPILER"" goto not_C_COMPILER
+:C_COMPILER
echo.%C_COMPILER%
goto end
:not_C_COMPILER
-if not "%1" == "C_PREPROC" goto not_C_PREPROC
+if "%1" == "C_PREPROC" goto C_PREPROC
+if not "%1" == ""C_PREPROC"" goto not_C_PREPROC
+:C_PREPROC
echo.%C_PREPROC%
goto end
:not_C_PREPROC
-if not "%1" == "FLAGS_OBJ" goto not_FLAGS_OBJ
+if "%1" == "FLAGS_OBJ" goto FLAGS_OBJ
+if not "%1" == ""FLAGS_OBJ"" goto not_FLAGS_OBJ
+:FLAGS_OBJ
echo.%FLAGS_OBJ%
goto end
:not_FLAGS_OBJ
-if not "%1" == "FLAGS_DYN" goto not_FLAGS_DYN
+if "%1" == "FLAGS_DYN" goto FLAGS_DYN
+if not "%1" == ""FLAGS_DYN"" goto not_FLAGS_DYN
+:FLAGS_DYN
echo.%FLAGS_DYN%
goto end
:not_FLAGS_DYN
-if not "%1" == "FLAGS_LIB" goto not_FLAGS_LIB
+if "%1" == "FLAGS_LIB" goto FLAGS_LIB
+if not "%1" == ""FLAGS_LIB"" goto not_FLAGS_LIB
+:FLAGS_LIB
echo.%FLAGS_LIB%
goto end
:not_FLAGS_LIB
-if not "%1" == "FLAGS_EXE" goto not_FLAGS_EXE
+if "%1" == "FLAGS_EXE" goto FLAGS_EXE
+if not "%1" == ""FLAGS_EXE"" goto not_FLAGS_EXE
+:FLAGS_EXE
echo.%FLAGS_EXE%
goto end
:not_FLAGS_EXE
-if not "%1" == "DEFS_OBJ" goto not_DEFS_OBJ
+if "%1" == "DEFS_OBJ" goto DEFS_OBJ
+if not "%1" == ""DEFS_OBJ"" goto not_DEFS_OBJ
+:DEFS_OBJ
echo.%DEFS_OBJ%
goto end
:not_DEFS_OBJ
-if not "%1" == "DEFS_DYN" goto not_DEFS_DYN
+if "%1" == "DEFS_DYN" goto DEFS_DYN
+if not "%1" == ""DEFS_DYN"" goto not_DEFS_DYN
+:DEFS_DYN
echo.%DEFS_DYN%
goto end
:not_DEFS_DYN
-if not "%1" == "DEFS_LIB" goto not_DEFS_LIB
+if "%1" == "DEFS_LIB" goto DEFS_LIB
+if not "%1" == ""DEFS_LIB"" goto not_DEFS_LIB
+:DEFS_LIB
echo.%DEFS_LIB%
goto end
:not_DEFS_LIB
-if not "%1" == "DEFS_EXE" goto not_DEFS_EXE
+if "%1" == "DEFS_EXE" goto DEFS_EXE
+if not "%1" == ""DEFS_EXE"" goto not_DEFS_EXE
+:DEFS_EXE
echo.%DEFS_EXE%
goto end
:not_DEFS_EXE
-if not "%1" == "BUILD_OBJ" goto not_BUILD_OBJ
+if "%1" == "BUILD_OBJ" goto BUILD_OBJ
+if not "%1" == ""BUILD_OBJ"" goto not_BUILD_OBJ
+:BUILD_OBJ
echo.%BUILD_OBJ%
goto end
:not_BUILD_OBJ
-if not "%1" == "BUILD_DYN" goto not_BUILD_DYN
+if "%1" == "BUILD_DYN" goto BUILD_DYN
+if not "%1" == ""BUILD_DYN"" goto not_BUILD_DYN
+:BUILD_DYN
echo.%BUILD_DYN%
goto end
:not_BUILD_DYN
-if not "%1" == "BUILD_LIB" goto not_BUILD_LIB
+if "%1" == "BUILD_LIB" goto BUILD_LIB
+if not "%1" == ""BUILD_LIB"" goto not_BUILD_LIB
+:BUILD_LIB
echo.%BUILD_LIB%
goto end
:not_BUILD_LIB
-if not "%1" == "BUILD_EXE" goto not_BUILD_EXE
+if "%1" == "BUILD_EXE" goto BUILD_EXE
+if not "%1" == ""BUILD_EXE"" goto not_BUILD_EXE
+:BUILD_EXE
echo.%BUILD_EXE%
goto end
:not_BUILD_EXE
-if not "%1" == "DEFS" goto not_DEFS
+if "%1" == "DEFS" goto DEFS
+if not "%1" == ""DEFS"" goto not_DEFS
+:DEFS
echo.%DEFS%
goto end
:not_DEFS
-if not "%1" == "LIBS" goto not_LIBS
+if "%1" == "LIBS" goto LIBS
+if not "%1" == ""LIBS"" goto not_LIBS
+:LIBS
echo.%LIBS%
goto end
:not_LIBS
-if not "%1" == "GAMBCLIB_DEFS" goto not_GAMBCLIB_DEFS
+if "%1" == "GAMBCLIB_DEFS" goto GAMBCLIB_DEFS
+if not "%1" == ""GAMBCLIB_DEFS"" goto not_GAMBCLIB_DEFS
+:GAMBCLIB_DEFS
echo.%GAMBCLIB_DEFS%
goto end
:not_GAMBCLIB_DEFS
-if not "%1" == "GAMBCLIB" goto not_GAMBCLIB
+if "%1" == "GAMBCLIB" goto GAMBCLIB
+if not "%1" == ""GAMBCLIB"" goto not_GAMBCLIB
+:GAMBCLIB
echo.%GAMBCLIB%
goto end
:not_GAMBCLIB
-if not "%1" == "GAMBCGSCLIB" goto not_GAMBCGSCLIB
+if "%1" == "GAMBCGSCLIB" goto GAMBCGSCLIB
+if not "%1" == ""GAMBCGSCLIB"" goto not_GAMBCGSCLIB
+:GAMBCGSCLIB
echo.%GAMBCGSCLIB%
goto end
:not_GAMBCGSCLIB
-if not "%1" == "GAMBCGSILIB" goto not_GAMBCGSILIB
+if "%1" == "GAMBCGSILIB" goto GAMBCGSILIB
+if not "%1" == ""GAMBCGSILIB"" goto not_GAMBCGSILIB
+:GAMBCGSILIB
echo.%GAMBCGSILIB%
goto end
:not_GAMBCGSILIB
-if not "%1" == "LIB_PREFIX" goto not_LIB_PREFIX
+if "%1" == "LIB_PREFIX" goto LIB_PREFIX
+if not "%1" == ""LIB_PREFIX"" goto not_LIB_PREFIX
+:LIB_PREFIX
echo.%LIB_PREFIX%
goto end
:not_LIB_PREFIX
-if not "%1" == "LIB_EXTENSION" goto not_LIB_EXTENSION
+if "%1" == "LIB_EXTENSION" goto LIB_EXTENSION
+if not "%1" == ""LIB_EXTENSION"" goto not_LIB_EXTENSION
+:LIB_EXTENSION
echo.%LIB_EXTENSION%
goto end
:not_LIB_EXTENSION
View
4 include/stamp.h
@@ -2,5 +2,5 @@
* Time stamp of last source code repository commit.
*/
-#define ___STAMP_YMD 20120122
-#define ___STAMP_HMS 20826
+#define ___STAMP_YMD 20120126
+#define ___STAMP_HMS 153712
View
135 lib/os_io.c
@@ -1,6 +1,6 @@
/* File: "os_io.c" */
-/* Copyright (c) 1994-2011 by Marc Feeley, All Rights Reserved. */
+/* Copyright (c) 1994-2012 by Marc Feeley, All Rights Reserved. */
/*
* This module implements the operating system specific routines
@@ -6724,8 +6724,11 @@ ___BOOL use_pty;)
#endif
+
#ifdef USE_CreateProcess
+#define ___ESCAPE_PROCESS_ARGS
+
___STRING_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) argv_to_ccmd
___P((___STRING_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) *argv),
(argv)
@@ -6736,82 +6739,94 @@ ___STRING_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) *argv;)
int i = 0;
___STRING_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) arg;
- while ((arg = argv[i++]) != NULL)
+ while ((arg = argv[i]) != NULL)
{
- int nb_preceding_backslashes = 0;
- int esc = 0;
int j = 0;
- ___CHAR_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) c;
- while ((c = arg[j++]) != ___UNICODE_NUL)
- {
-#ifndef ___DOUBLE_QUOTE_PROGRAM_ARGS
- if (i == 0) /* only double quote program name */
-#endif
- {
- if (c == ___UNICODE_BACKSLASH)
- nb_preceding_backslashes++;
- else
- {
- if (c == ___UNICODE_DOUBLEQUOTE)
- esc += nb_preceding_backslashes + 1;
- nb_preceding_backslashes = 0;
- }
- }
- }
-#ifndef ___DOUBLE_QUOTE_PROGRAM_ARGS
- if (i == 0) /* only double quote program name */
+
+ while (arg[j] != ___UNICODE_NUL)
+ j++;
+
+ ccmd_len += j + 1;
+
+#ifdef ___ESCAPE_PROCESS_ARGS
+
+ {
+ ___BOOL double_backslash = TRUE;
+
+ while (--j >= 0)
+ {
+ ___CHAR_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) c = arg[j];
+ if (c == ___UNICODE_DOUBLEQUOTE ||
+ (double_backslash && c == ___UNICODE_BACKSLASH))
+ {
+ double_backslash = TRUE;
+ ccmd_len++;
+ }
+ else
+ double_backslash = FALSE;
+ }
+
+ ccmd_len += 2;
+ }
+
#endif
- esc += nb_preceding_backslashes + 2; /* add begin/end quotes */
- ccmd_len += j + esc; /* account for escapes */
+
+ i++;
}
ccmd = ___CAST(___STRING_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT),
___alloc_mem (ccmd_len * sizeof (*ccmd)));
if (ccmd != NULL)
{
- ___STRING_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) p = ccmd;
- i = 0;
+ ccmd[--ccmd_len] = ___UNICODE_NUL;
- while ((arg = argv[i++]) != NULL)
+ while (--i >= 0)
{
- int nb_preceding_backslashes = 0;
int j = 0;
- ___CHAR_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) c;
-#ifndef ___DOUBLE_QUOTE_PROGRAM_ARGS
- if (i == 0) /* only double quote program name */
-#endif
- *p++ = ___UNICODE_DOUBLEQUOTE;
- while ((c = arg[j++]) != ___UNICODE_NUL)
+
+ arg = argv[i];
+
+ while (arg[j] != ___UNICODE_NUL)
+ j++;
+
+#ifdef ___ESCAPE_PROCESS_ARGS
+
+ {
+ ___BOOL double_backslash = TRUE;
+
+ ccmd[--ccmd_len] = ___UNICODE_DOUBLEQUOTE;
+
+ while (--j >= 0)
+ {
+ ___CHAR_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) c = arg[j];
+ ccmd[--ccmd_len] = c;
+ if (c == ___UNICODE_DOUBLEQUOTE ||
+ (double_backslash && c == ___UNICODE_BACKSLASH))
+ {
+ ccmd[--ccmd_len] = ___UNICODE_BACKSLASH;
+ double_backslash = TRUE;
+ }
+ else
+ double_backslash = FALSE;
+ }
+
+ ccmd[--ccmd_len] = ___UNICODE_DOUBLEQUOTE;
+ }
+
+#else
+
+ while (--j >= 0)
{
-#ifndef ___DOUBLE_QUOTE_PROGRAM_ARGS
- if (i == 0) /* only double quote program name */
-#endif
- {
- if (c == ___UNICODE_BACKSLASH)
- nb_preceding_backslashes++;
- else
- {
- if (c == ___UNICODE_DOUBLEQUOTE)
- while (nb_preceding_backslashes-- >= 0)
- *p++ = ___UNICODE_BACKSLASH;
- nb_preceding_backslashes = 0;
- }
- }
- *p++ = c;
+ ___CHAR_TYPE(___STREAM_OPEN_PROCESS_CE_SELECT) c = arg[j];
+ ccmd[--ccmd_len] = c;
}
-#ifndef ___DOUBLE_QUOTE_PROGRAM_ARGS
- if (i == 0) /* only double quote program name */
+
#endif
- {
- while (nb_preceding_backslashes-- > 0)
- *p++ = ___UNICODE_BACKSLASH;
- *p++ = ___UNICODE_DOUBLEQUOTE;
- }
- *p++ = ___UNICODE_SPACE;
- }
- p[-1] = ___UNICODE_NUL;
+ if (i > 0)
+ ccmd[--ccmd_len] = ___UNICODE_SPACE;
+ }
}
return ccmd;

0 comments on commit 747c3e3

Please sign in to comment.
Something went wrong with that request. Please try again.