winpr/process: handle pids <= 0
authorBernhard Miklautz <bernhard.miklautz@thincast.com>
Mon, 9 Feb 2015 13:07:14 +0000 (14:07 +0100)
committerBernhard Miklautz <bernhard.miklautz@thincast.com>
Mon, 9 Feb 2015 13:07:14 +0000 (14:07 +0100)
TerminateProcess shouldn't call kill if the PID is <=0 because this has
unwanted effects (and is not what TerminateProcess should do):

* with PID == 0 any process in the same process group gets the signal
  sent
* with PID == -1 *every* processes that the running users has
  permissions to gets the signal sent
* with PID < -1 the process within the same process group and -PID gets
  the signal send

For more details see kill(2).

winpr/libwinpr/thread/process.c

index ab2aab4..cc53276 100644 (file)
@@ -448,7 +448,7 @@ BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode)
 
        process = (WINPR_PROCESS*) hProcess;
 
-       if (!process)
+       if (!process || (process->pid <= 0))
                return FALSE;
 
        if (kill(process->pid, SIGTERM))