Merge pull request #1611 from bmiklautz/createProcess

winpr-thread: fixed bugs in _CreateProcessExA
This commit is contained in:
Marc-André Moreau 2013-11-22 06:13:05 -08:00
commit 63ff9255fd

View File

@ -180,13 +180,14 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
pid_t pid;
int flags;
int numArgs;
LPSTR* pArgs;
char** envp;
LPSTR* pArgs = NULL;
char** envp = NULL;
char* filename = NULL;
WINPR_THREAD* thread;
WINPR_PROCESS* process;
WINPR_ACCESS_TOKEN* token;
LPTCH lpszEnvironmentBlock;
BOOL ret = FALSE;
pid = 0;
envp = NULL;
@ -210,6 +211,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
}
filename = FindApplicationPath(pArgs[0]);
if (NULL == filename)
goto finish;
/* fork and exec */
@ -218,7 +221,7 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
if (pid < 0)
{
/* fork failure */
return FALSE;
goto finish;
}
if (pid == 0)
@ -252,7 +255,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
if (execve(filename, pArgs, envp) < 0)
{
return FALSE;
/* execve failed - end the process */
_exit(1);
}
}
else
@ -263,7 +267,9 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
process = (WINPR_PROCESS*) malloc(sizeof(WINPR_PROCESS));
if (!process)
return FALSE;
{
goto finish;
}
ZeroMemory(process, sizeof(WINPR_PROCESS));
@ -278,7 +284,9 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
ZeroMemory(thread, sizeof(WINPR_THREAD));
if (!thread)
return FALSE;
{
goto finish;
}
WINPR_HANDLE_SET_TYPE(thread, HANDLE_TYPE_THREAD);
@ -289,7 +297,13 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
lpProcessInformation->dwProcessId = (DWORD) pid;
lpProcessInformation->dwThreadId = (DWORD) pid;
free(filename);
ret = TRUE;
finish:
if (filename)
{
free(filename);
}
if (pArgs)
{
@ -312,7 +326,7 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
free(envp);
}
return TRUE;
return ret;
}
BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,