Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Fix for Windows spawner and starter

Index: ChangeLog
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.win32/ChangeLog,v
retrieving revision 1.4
diff -u -r1.4 ChangeLog
--- ChangeLog	19 Nov 2002 18:53:48 -0000	1.4
+++ ChangeLog	13 Jan 2003 19:26:43 -0000
@@ -1,3 +1,10 @@
+2003-01-13 Alex Chapiro
+
+	* os/win32/x86/spawner.dll: Rebuild.
+	* os/win32/x86/starter.exe: Rebuild.
+	* library/Win32ProcessEx.c: Quoting of spaces when calling starter.
+	* library/starter/starter.cpp: Quoting of spaces when calling the executable.
+
 2002-11-06 Alex Chapiro
 
 	* library/Win32ProcessEx.c:
Index: library/Win32ProcessEx.c
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c,v
retrieving revision 1.5
diff -u -r1.5 Win32ProcessEx.c
--- library/Win32ProcessEx.c	19 Nov 2002 18:53:30 -0000	1.5
+++ library/Win32ProcessEx.c	13 Jan 2003 19:26:44 -0000
@@ -22,7 +22,7 @@
 #include "jni.h"
 #include "io.h"
 
-// #define DEBUG_MONITOR
+//#define DEBUG_MONITOR
 
 #define PIPE_SIZE 512
 #define MAX_CMD_SIZE 1024
@@ -96,7 +96,7 @@
 	char eventWaitName[20];
 	char eventTerminateName[20];
 #ifdef DEBUG_MONITOR
-	char buffer[100];
+	char buffer[1000];
 #endif
 
 
@@ -179,16 +179,11 @@
 			{
 			jobject item = (*env) -> GetObjectArrayElement(env, envp, i);
 			jsize    len = (*env) -> GetStringUTFLength(env, item);
-			int nCpyLen;
 			const char *  str = (*env) -> GetStringUTFChars(env, item, 0);	
 			if(NULL != str)
 				{
-				if(0 > (nCpyLen = copyTo(szEnvBlock + nPos, str, len, MAX_ENV_SIZE - nPos - 1)))
-					{
-					ThrowByName(env, "java/Exception", "Too many environment variables");
-					return 0;
-					}
-				nPos += nCpyLen;
+				strncpy(szEnvBlock + nPos, str, len);
+				nPos += len;
 				szEnvBlock[nPos] = '\0';
 				++nPos;
 				(*env) -> ReleaseStringUTFChars(env, item, str);
@@ -387,16 +382,11 @@
 			{
 			jobject item = (*env) -> GetObjectArrayElement(env, envp, i);
 			jsize    len = (*env) -> GetStringUTFLength(env, item);
-			int nCpyLen;
 			const char *  str = (*env) -> GetStringUTFChars(env, item, 0);	
 			if(NULL != str)
 				{
-				if(0 > (nCpyLen = copyTo(szEnvBlock + nPos, str, len, MAX_ENV_SIZE - nPos - 1)))
-					{
-					ThrowByName(env, "java/Exception", "Too many environment variables");
-					return 0;
-					}
-				nPos += nCpyLen;
+				strncpy(szEnvBlock + nPos, str, len);
+				nPos += len;
 				szEnvBlock[nPos] = '\0';
 				++nPos;
 				(*env) -> ReleaseStringUTFChars(env, item, str);
@@ -664,7 +654,7 @@
 	int pid = *(int *)pv;
 	DWORD rc = 0;
 #ifdef DEBUG_MONITOR
-	char buffer[100];
+	char buffer[1000];
 #endif
 
 	HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
@@ -710,36 +700,46 @@
 // Return number of bytes in target or -1 in case of error
 int copyTo(char * target, const char * source, int cpyLength, int availSpace)
 {
+#ifdef DEBUG_MONITOR
+	char buffer[1000];
+#endif
 	BOOL bSlash = FALSE;
-	int i, j;
+	int i = 0, j = 0;
 	int totCpyLength = cpyLength;
+	BOOL bQoutedTerm = FALSE;
 
 	if(availSpace < cpyLength)
 		return -1;
-	strncpy(target, source, cpyLength);
-	return cpyLength;
+	//strncpy(target, source, cpyLength);
+	//return cpyLength;
+
+	if(('\"' == *source) && ('\"' == *(source + cpyLength)))
+		bQoutedTerm = TRUE; // Already quoted
+	else
+	if(strchr(source, ' ') == NULL)
+		bQoutedTerm = TRUE; // No reason to quotate term becase it doesn't have embedded spaces
+	else
+		{
+		*target = '\"';
+		++j;
+		}
 
-	// Don't open this feature for a while
 
-	for(i = 0, j = 0; i < cpyLength; ++i, ++j) 
+	for(; i < cpyLength; ++i, ++j) 
 		{
 		if(source[i] == '\\')
 			bSlash = TRUE;
 		else
-		if(source[i] == '"') 
+		if((source[i] == '\"') && (!bQoutedTerm || (i != 0) || i != (cpyLength)) ) 
 			{
-			if(bSlash)
+			if(!bSlash)
 				{
 				if(j == availSpace)
 					return -1;
 				target[j] = '\\';
 				++j;
-				bSlash = FALSE;
 				}
-			if(j == availSpace)
-				return -1;
-			target[j] = '\\';
-			++j;
+			bSlash = FALSE;
 			}
 		else
 			bSlash = FALSE;
@@ -749,6 +749,18 @@
 		target[j] = source[i];
 		}
 
+	if(!bQoutedTerm)
+		{
+		if(j == availSpace)
+			return -1;
+		target[j] = '\"';
+		++j;
+		}
+
+#ifdef DEBUG_MONITOR
+	sprintf(buffer, "copyTo: %s %d %d\n", source, j, cpyLength);
+	OutputDebugString(buffer);
+#endif
 	return j;
 }
 
Index: library/starter/starter.cpp
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.win32/library/starter/starter.cpp,v
retrieving revision 1.1
diff -u -r1.1 starter.cpp
--- library/starter/starter.cpp	3 Sep 2002 16:16:20 -0000	1.1
+++ library/starter/starter.cpp	13 Jan 2003 19:26:44 -0000
@@ -26,6 +26,8 @@
 // #define DEBUG_MONITOR
 #define MAX_CMD_LINE_LENGTH (1024)
 
+int copyTo(char * target, const char * source, int cpyLength, int availSpace);
+
 ///////////////////////////////////////////////////////////////////////////////
 BOOL WINAPI HandlerRoutine(  DWORD dwCtrlType)   //  control signal type
 {
@@ -64,6 +66,24 @@
 
    // Construct the full command line
    TCHAR szCmdLine[MAX_CMD_LINE_LENGTH] = { 0 };
+   int nPos = 0;
+
+   for(int i = 4; i < argc; ++i) 
+		{
+		int nCpyLen;
+		if(0 > (nCpyLen = copyTo(szCmdLine + nPos, argv[i], _tcslen(argv[i]), MAX_CMD_LINE_LENGTH - nPos)))
+			{
+#ifdef DEBUG_MONITOR
+			OutputDebugString("Not enough space to build command line\n");
+#endif
+			return 0;
+			}
+		nPos += nCpyLen;
+		szCmdLine[nPos] = _T(' ');
+		++nPos;
+		}   
+   szCmdLine[nPos] = _T('\0');
+/*   
    for (int i = 4; i < argc; i++) {
 	  if(sizeof(szCmdLine) > (_tcslen(szCmdLine) + _tcslen(argv[i]))) 
 		{
@@ -75,6 +95,7 @@
 		OutputDebugString("Command line is too long\n");
 #endif
    }
+*/
 
    STARTUPINFO         si = { sizeof(si) };
    PROCESS_INFORMATION pi = { 0 };
@@ -172,6 +193,67 @@
  
    return(dwExitCode);
 }
+
+// Return number of bytes in target or -1 in case of error
+int copyTo(LPTSTR target, LPCTSTR source, int cpyLength, int availSpace)
+{
+	BOOL bSlash = FALSE;
+	int i = 0, j = 0;
+	int totCpyLength = cpyLength;
+	BOOL bQoutedTerm = FALSE;
+
+	if(availSpace < cpyLength)
+		return -1;
+//	strncpy(target, source, cpyLength);
+//	return cpyLength;
+
+	if((_T('\"') == *source) && (_T('\"') == *(source + cpyLength)))
+		bQoutedTerm = TRUE; // Already quoted
+	else
+	if(_tcschr(source, _T(' ')) == NULL)
+		bQoutedTerm = TRUE; // No reason to quotate term becase it doesn't have embedded spaces
+	else
+		{
+		*target = _T('\"');
+		++j;
+		}
+
+
+	for(; i < cpyLength; ++i, ++j) 
+		{
+		if(source[i] == _T('\\'))
+			bSlash = TRUE;
+		else
+		if((source[i] == _T('\"')) && (!bQoutedTerm || (i != 0) || i != (cpyLength)) ) 
+			{
+			if(!bSlash)
+				{
+				if(j == availSpace)
+					return -1;
+				target[j] = _T('\\');
+				++j;
+				}
+			bSlash = FALSE;
+			}
+		else
+			bSlash = FALSE;
+
+		if(j == availSpace)
+			return -1;
+		target[j] = source[i];
+		}
+
+	if(!bQoutedTerm)
+		{
+		if(j == availSpace)
+			return -1;
+		target[j] = _T('\"');
+		++j;
+		}
+
+	return j;
+}
+
 
 
 //////////////////////////////// End of File //////////////////////////////////
Index: os/win32/x86/spawner.dll
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.win32/os/win32/x86/spawner.dll,v
retrieving revision 1.7
diff -u -r1.7 spawner.dll
Binary files /tmp/cvsiiOGSy and spawner.dll differ
Index: os/win32/x86/starter.exe
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe,v
retrieving revision 1.3
diff -u -r1.3 starter.exe
Binary files /tmp/cvsQerdpv and starter.exe differ



Back to the top