Merge pull request #1611 from bmiklautz/createProcess
winpr-thread: fixed bugs in _CreateProcessExA
This commit is contained in:
commit
63ff9255fd
@ -180,13 +180,14 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
int flags;
|
int flags;
|
||||||
int numArgs;
|
int numArgs;
|
||||||
LPSTR* pArgs;
|
LPSTR* pArgs = NULL;
|
||||||
char** envp;
|
char** envp = NULL;
|
||||||
char* filename = NULL;
|
char* filename = NULL;
|
||||||
WINPR_THREAD* thread;
|
WINPR_THREAD* thread;
|
||||||
WINPR_PROCESS* process;
|
WINPR_PROCESS* process;
|
||||||
WINPR_ACCESS_TOKEN* token;
|
WINPR_ACCESS_TOKEN* token;
|
||||||
LPTCH lpszEnvironmentBlock;
|
LPTCH lpszEnvironmentBlock;
|
||||||
|
BOOL ret = FALSE;
|
||||||
|
|
||||||
pid = 0;
|
pid = 0;
|
||||||
envp = NULL;
|
envp = NULL;
|
||||||
@ -210,6 +211,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
filename = FindApplicationPath(pArgs[0]);
|
filename = FindApplicationPath(pArgs[0]);
|
||||||
|
if (NULL == filename)
|
||||||
|
goto finish;
|
||||||
|
|
||||||
/* fork and exec */
|
/* fork and exec */
|
||||||
|
|
||||||
@ -218,7 +221,7 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
/* fork failure */
|
/* fork failure */
|
||||||
return FALSE;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid == 0)
|
if (pid == 0)
|
||||||
@ -252,7 +255,8 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
|
|
||||||
if (execve(filename, pArgs, envp) < 0)
|
if (execve(filename, pArgs, envp) < 0)
|
||||||
{
|
{
|
||||||
return FALSE;
|
/* execve failed - end the process */
|
||||||
|
_exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -263,7 +267,9 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
process = (WINPR_PROCESS*) malloc(sizeof(WINPR_PROCESS));
|
process = (WINPR_PROCESS*) malloc(sizeof(WINPR_PROCESS));
|
||||||
|
|
||||||
if (!process)
|
if (!process)
|
||||||
return FALSE;
|
{
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
ZeroMemory(process, sizeof(WINPR_PROCESS));
|
ZeroMemory(process, sizeof(WINPR_PROCESS));
|
||||||
|
|
||||||
@ -278,7 +284,9 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
ZeroMemory(thread, sizeof(WINPR_THREAD));
|
ZeroMemory(thread, sizeof(WINPR_THREAD));
|
||||||
|
|
||||||
if (!thread)
|
if (!thread)
|
||||||
return FALSE;
|
{
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
WINPR_HANDLE_SET_TYPE(thread, HANDLE_TYPE_THREAD);
|
WINPR_HANDLE_SET_TYPE(thread, HANDLE_TYPE_THREAD);
|
||||||
|
|
||||||
@ -289,7 +297,13 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
lpProcessInformation->dwProcessId = (DWORD) pid;
|
lpProcessInformation->dwProcessId = (DWORD) pid;
|
||||||
lpProcessInformation->dwThreadId = (DWORD) pid;
|
lpProcessInformation->dwThreadId = (DWORD) pid;
|
||||||
|
|
||||||
free(filename);
|
ret = TRUE;
|
||||||
|
|
||||||
|
finish:
|
||||||
|
if (filename)
|
||||||
|
{
|
||||||
|
free(filename);
|
||||||
|
}
|
||||||
|
|
||||||
if (pArgs)
|
if (pArgs)
|
||||||
{
|
{
|
||||||
@ -312,7 +326,7 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||||||
free(envp);
|
free(envp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
BOOL CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes,
|
||||||
|
Loading…
Reference in New Issue
Block a user