diff options
author | Alain Magloire | 2003-03-11 20:07:05 +0000 |
---|---|---|
committer | Alain Magloire | 2003-03-11 20:07:05 +0000 |
commit | e3e6b03fb1037fb1f9ce201781b6e8f7cc7786df (patch) | |
tree | 0dbc5de855c8ab759032f3c3ec537e61860eb296 | |
parent | 3bfd24bee516ec33d7ef52165c4459d8ff90f5d8 (diff) | |
download | org.eclipse.cdt-e3e6b03fb1037fb1f9ce201781b6e8f7cc7786df.tar.gz org.eclipse.cdt-e3e6b03fb1037fb1f9ce201781b6e8f7cc7786df.tar.xz org.eclipse.cdt-e3e6b03fb1037fb1f9ce201781b6e8f7cc7786df.zip |
Multiple fix from Alex Chapiro moved from the head
to the branch.
-rw-r--r-- | core/org.eclipse.cdt.core.win32/ChangeLog | 43 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.win32/build.properties | 9 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c | 134 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.win32/library/starter/starter.cpp | 94 | ||||
-rw-r--r-- | core/org.eclipse.cdt.core.win32/os/win32/x86/spawner.dll | bin | 53248 -> 53248 bytes | |||
-rw-r--r-- | core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe | bin | 16384 -> 16384 bytes |
6 files changed, 230 insertions, 50 deletions
diff --git a/core/org.eclipse.cdt.core.win32/ChangeLog b/core/org.eclipse.cdt.core.win32/ChangeLog index f99858b0846..4320321bc7a 100644 --- a/core/org.eclipse.cdt.core.win32/ChangeLog +++ b/core/org.eclipse.cdt.core.win32/ChangeLog @@ -1,3 +1,46 @@ +2003-02-25 Alex Chapiro + + Fix for this type of problem: + make CFLAGS="-D jek " + + * os/win32/x86/spawner.dll: Rebuild + * os/win32/x86/starter.exe: Rebuild + * src/library/starter/starter.cpp: + Fix problem with embedded quotation + * src/library/Win32ProcessEx.c: + Fix problem with embedded quotation. + +2003-01-27 Alex Chapiro + + * os/win32/x86/spawner.dll: Rebuild + * src/library/Win32ProcessEx.c: Synchronization error fix. + +2003-01-23 Alex Chapiro + + * os/win32/x86/spawner.dll: Rebuild + * os/win32/x86/starter.exe: Rebuild + * src/library/starter/starter.cpp: + Correct quotation escaped. + * src/library/Win32ProcessEx.c: + Correct quotation escaped. + +2003-01-17 Alex Chapiro + + * os/win32/x86/spawner.dll: Rebuild + * os/win32/x86/starter.exe: Rebuild + * src/library/starter/starter.cpp (copyTo): + Check for overflow. + * src/library/Win32ProcessEx.c (..exec1 exec0): + Dynamically allocate environment buffer to avoid overflow. + Check for overflow. + +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: diff --git a/core/org.eclipse.cdt.core.win32/build.properties b/core/org.eclipse.cdt.core.win32/build.properties index 13040229c19..ca4d06b082b 100644 --- a/core/org.eclipse.cdt.core.win32/build.properties +++ b/core/org.eclipse.cdt.core.win32/build.properties @@ -1,4 +1,9 @@ bin.includes = fragment.xml,\ - os/,\ - fragment.properties + fragment.properties,\ + about.html,\ + os/ +src.includes = fragment.xml,\ + fragment.properties,\ + about.html,\ + os/ source.cdt_win32.jar = src/ diff --git a/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c b/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c index 1c7d9cd0455..af32311049a 100644 --- a/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c +++ b/core/org.eclipse.cdt.core.win32/library/Win32ProcessEx.c @@ -85,7 +85,8 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 LPVOID envBlk = NULL;
int ret = 0;
char szCmdLine[MAX_CMD_SIZE];
- char szEnvBlock[MAX_ENV_SIZE];
+ int nBlkSize = MAX_ENV_SIZE;
+ char * szEnvBlock = (char *)malloc(nBlkSize);
jsize nCmdTokens = 0;
jsize nEnvVars = 0;
int i;
@@ -96,7 +97,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 char eventWaitName[20];
char eventTerminateName[20];
#ifdef DEBUG_MONITOR
- char buffer[100];
+ char buffer[1000];
#endif
@@ -150,6 +151,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 nPos = sprintf(szCmdLine, "%sstarter.exe %s %s %s ", path, eventBreakName, eventWaitName, eventTerminateName);
+ // Prepare command line
for(i = 0; i < nCmdTokens; ++i)
{
jobject item = (*env) -> GetObjectArrayElement(env, cmdarray, i);
@@ -160,7 +162,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 {
if(0 > (nCpyLen = copyTo(szCmdLine + nPos, str, len, MAX_CMD_SIZE - nPos)))
{
- ThrowByName(env, "java/Exception", "Too long command line");
+ ThrowByName(env, "java/lang/Exception", "Too long command line");
return 0;
}
nPos += nCpyLen;
@@ -172,6 +174,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 szCmdLine[nPos] = '\0';
+ // Prepare environment block
if (nEnvVars > 0)
{
nPos = 0;
@@ -179,16 +182,26 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 {
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)))
+ while((nBlkSize - nPos) <= (len + 2)) // +2 for two '\0'
{
- ThrowByName(env, "java/Exception", "Too many environment variables");
- return 0;
+ nBlkSize += MAX_ENV_SIZE;
+ szEnvBlock = (char *)realloc(szEnvBlock, nBlkSize);
+ if(NULL == szEnvBlock)
+ {
+ ThrowByName(env, "java/lang/Exception", "Not enough memory");
+ return 0;
+ }
+#ifdef DEBUG_MONITOR
+ sprintf(buffer, "Realloc environment block; new length is %i \n", nBlkSize);
+ OutputDebugString(buffer);
+#endif
+
}
- nPos += nCpyLen;
+ strncpy(szEnvBlock + nPos, str, len);
+ nPos += len;
szEnvBlock[nPos] = '\0';
++nPos;
(*env) -> ReleaseStringUTFChars(env, item, str);
@@ -249,7 +262,8 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 if(NULL != cwd)
free(cwd);
-
+
+ free(szEnvBlock);
CloseHandle(hread[0]);
CloseHandle(hwrite[1]);
@@ -294,7 +308,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec0 pCurProcInfo -> pid = pi.dwProcessId;
h[0] = pCurProcInfo -> eventWait;
h[1] = (HANDLE)_beginthreadex(NULL, 0, waitProcTermination,
- (void *) &(pi.dwProcessId), 0, (UINT*) &dwThreadId);
+ (void *) pi.dwProcessId, 0, (UINT*) &dwThreadId);
what = WaitForMultipleObjects(2, h, FALSE, INFINITE);
if((what != WAIT_OBJECT_0) && (pCurProcInfo -> pid > 0)) // CreateProcess failed
@@ -345,7 +359,8 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 int i;
int nPos;
char szCmdLine[MAX_CMD_SIZE];
- char szEnvBlock[MAX_ENV_SIZE];
+ int nBlkSize = MAX_ENV_SIZE;
+ char * szEnvBlock = (char *)malloc(nBlkSize);
sa.nLength = sizeof(sa);
@@ -358,6 +373,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 nPos = 0;
+ // Prepare command line
for(i = 0; i < nCmdTokens; ++i)
{
jobject item = (*env) -> GetObjectArrayElement(env, cmdarray, i);
@@ -368,7 +384,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 {
if(0 > (nCpyLen = copyTo(szCmdLine + nPos, str, len, MAX_CMD_SIZE - nPos)))
{
- ThrowByName(env, "java/Exception", "Too long command line");
+ ThrowByName(env, "java/lang/Exception", "Too long command line");
return 0;
}
nPos += nCpyLen;
@@ -380,6 +396,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 szCmdLine[nPos] = '\0';
+ // Prepare environment block
if (nEnvVars > 0)
{
nPos = 0;
@@ -387,16 +404,21 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 {
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)))
+ while((nBlkSize - nPos) <= (len + 2)) // +2 for two '\0'
{
- ThrowByName(env, "java/Exception", "Too many environment variables");
- return 0;
+ nBlkSize += MAX_ENV_SIZE;
+ szEnvBlock = (char *)realloc(szEnvBlock, nBlkSize);
+ if(NULL == szEnvBlock)
+ {
+ ThrowByName(env, "java/lang/Exception", "Not enough memory");
+ return 0;
+ }
}
- nPos += nCpyLen;
+ strncpy(szEnvBlock + nPos, str, len);
+ nPos += len;
szEnvBlock[nPos] = '\0';
++nPos;
(*env) -> ReleaseStringUTFChars(env, item, str);
@@ -443,6 +465,7 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_exec1 if(NULL != cwd)
free(cwd);
+ free(szEnvBlock);
if (!ret)
{
@@ -486,12 +509,15 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise pProcInfo_t pCurProcInfo = findProcInfo(uid);
#ifdef DEBUG_MONITOR
char buffer[100];
- sprintf(buffer, "Spawner received signal %i for process %i\n", signal, pCurProcInfo -> pid);
- OutputDebugString(buffer);
#endif
if(NULL == pCurProcInfo)
return -1;
+
+#ifdef DEBUG_MONITOR
+ sprintf(buffer, "Spawner received signal %i for process %i\n", signal, pCurProcInfo -> pid);
+ OutputDebugString(buffer);
+#endif
hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, pCurProcInfo -> pid);
@@ -661,10 +687,10 @@ void cleanUpProcBlock(pProcInfo_t pCurProcInfo) unsigned int _stdcall waitProcTermination(void* pv)
{
int i;
- int pid = *(int *)pv;
+ 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);
@@ -711,44 +737,72 @@ unsigned int _stdcall waitProcTermination(void* pv) int copyTo(char * target, const char * source, int cpyLength, int availSpace)
{
BOOL bSlash = FALSE;
- int i, j;
+ int i = 0, j = 0;
int totCpyLength = cpyLength;
- if(availSpace < cpyLength)
+#define QUOTATION_DO 0
+#define QUOTATION_DONE 1
+#define QUOTATION_NONE 2
+
+ int nQuotationMode = 0;
+
+
+
+ if(availSpace <= cpyLength) // = to reserve space for final '\0'
return -1;
- strncpy(target, source, cpyLength);
- return cpyLength;
- // Don't open this feature for a while
+ if(('\"' == *source) && ('\"' == *(source + cpyLength - 1)))
+ {
+ nQuotationMode = QUOTATION_DONE;
+ }
+ else
+ if(strchr(source, ' ') == NULL)
+ {
+ // No reason to quotate term becase it doesn't have embedded spaces
+ nQuotationMode = QUOTATION_NONE;
+ }
+ else
+ {
+ // Needs to be quotated
+ nQuotationMode = QUOTATION_DO;
+ *target = '\"';
+ ++j;
+ }
- for(i = 0, j = 0; i < cpyLength; ++i, ++j)
+
+ for(; i < cpyLength; ++i, ++j)
{
if(source[i] == '\\')
bSlash = TRUE;
else
- if(source[i] == '"')
{
- if(bSlash)
+ // Don't escape embracing quotation marks
+ if((source[i] == '\"') && !((nQuotationMode == QUOTATION_DONE) && ((i == 0) || (i == (cpyLength - 1))) ) )
{
- if(j == availSpace)
- return -1;
- target[j] = '\\';
- ++j;
- bSlash = FALSE;
+ if(!bSlash) // If still not escaped
+ {
+ if(j == availSpace)
+ return -1;
+ target[j] = '\\';
+ ++j;
+ }
}
- if(j == availSpace)
- return -1;
- target[j] = '\\';
- ++j;
- }
- else
bSlash = FALSE;
+ }
if(j == availSpace)
return -1;
target[j] = source[i];
}
+ if(nQuotationMode == QUOTATION_DO)
+ {
+ if(j == availSpace)
+ return -1;
+ target[j] = '\"';
+ ++j;
+ }
+
return j;
}
diff --git a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp index 96cb4a35c7a..81df10d8942 100644 --- a/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp +++ b/core/org.eclipse.cdt.core.win32/library/starter/starter.cpp @@ -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,17 +66,23 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) { // Construct the full command line
TCHAR szCmdLine[MAX_CMD_LINE_LENGTH] = { 0 };
- for (int i = 4; i < argc; i++) {
- if(sizeof(szCmdLine) > (_tcslen(szCmdLine) + _tcslen(argv[i])))
+ int nPos = 0;
+
+ for(int i = 4; i < argc; ++i)
{
- _tcscat(szCmdLine, argv[i]);
- _tcscat(szCmdLine, __TEXT(" "));
- }
+ int nCpyLen;
+ if(0 > (nCpyLen = copyTo(szCmdLine + nPos, argv[i], _tcslen(argv[i]), MAX_CMD_LINE_LENGTH - nPos)))
+ {
#ifdef DEBUG_MONITOR
- else
- OutputDebugString("Command line is too long\n");
+ OutputDebugString("Not enough space to build command line\n");
#endif
- }
+ return 0;
+ }
+ nPos += nCpyLen;
+ szCmdLine[nPos] = _T(' ');
+ ++nPos;
+ }
+ szCmdLine[nPos] = _T('\0');
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi = { 0 };
@@ -173,5 +181,75 @@ extern "C" int _tmain(int argc, TCHAR* argv[]) { 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;
+
+#define QUOTATION_DO 0
+#define QUOTATION_DONE 1
+#define QUOTATION_NONE 2
+
+ int nQuotationMode = 0;
+ if(availSpace <= cpyLength) // = to reserve space for '\0'
+ return -1;
+
+ if((_T('\"') == *source) && (_T('\"') == *(source + cpyLength - 1)))
+ {
+ // Already done
+ nQuotationMode = QUOTATION_DONE;
+ }
+ else
+ if(_tcschr(source, _T(' ')) == NULL)
+ {
+ // No reason to quotate term becase it doesn't have embedded spaces
+ nQuotationMode = QUOTATION_NONE;
+ }
+ else
+ {
+ // Needs to be quotated
+ nQuotationMode = QUOTATION_DO;
+ *target = _T('\"');
+ ++j;
+ }
+
+ for(; i < cpyLength; ++i, ++j)
+ {
+ if(source[i] == _T('\\'))
+ bSlash = TRUE;
+ else
+ // Don't escape embracing quotation marks
+ if((source[i] == _T('\"')) && !((nQuotationMode == QUOTATION_DONE) && ((i == 0) || (i == (cpyLength - 1))) ) )
+ {
+ 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(nQuotationMode == QUOTATION_DO)
+ {
+ if(j == availSpace)
+ return -1;
+ target[j] = _T('\"');
+ ++j;
+ }
+ return j;
+}
+
+
//////////////////////////////// End of File //////////////////////////////////
diff --git a/core/org.eclipse.cdt.core.win32/os/win32/x86/spawner.dll b/core/org.eclipse.cdt.core.win32/os/win32/x86/spawner.dll Binary files differindex b5bb06d727f..e11ce2c22f4 100644 --- a/core/org.eclipse.cdt.core.win32/os/win32/x86/spawner.dll +++ b/core/org.eclipse.cdt.core.win32/os/win32/x86/spawner.dll diff --git a/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe b/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe Binary files differindex 19011275b91..d81e602f73d 100644 --- a/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe +++ b/core/org.eclipse.cdt.core.win32/os/win32/x86/starter.exe |