diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-20 02:16:27 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2017-05-20 02:16:27 +0200 |
commit | 767787e655f26fbd731eec4b5eaf1e8c84e6828d (patch) | |
tree | 8fa91c17e74c8ab1274da1ca7bec5e96777b066a | |
parent | b76eacafa8e7c979448bd12e6ba2d5648d39aabf (diff) | |
download | psutil-767787e655f26fbd731eec4b5eaf1e8c84e6828d.tar.gz |
GetExitCodeProces() return code was not checked
-rw-r--r-- | psutil/arch/windows/process_info.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/psutil/arch/windows/process_info.c b/psutil/arch/windows/process_info.c index e951cb49..0ed8639e 100644 --- a/psutil/arch/windows/process_info.c +++ b/psutil/arch/windows/process_info.c @@ -196,14 +196,37 @@ psutil_handle_from_pid_waccess(DWORD pid, DWORD dwDesiredAccess) { return NULL; } - // make sure the process is running - GetExitCodeProcess(hProcess, &processExitCode); - if (processExitCode == 0) { - NoSuchProcess(); - CloseHandle(hProcess); + if (GetExitCodeProcess(hProcess, &processExitCode)) { + // XXX - maybe STILL_ACTIVE is not fully reliable as per: + // http://stackoverflow.com/questions/1591342/#comment47830782_1591379 + if (processExitCode == STILL_ACTIVE) { + if (! psutil_assert_pid_exists( + pid, "GetExitCodeProcess() -> STILL_ACTIVE but PID does " + "not exists")) { + return NULL; + } + return hProcess; + } + else { + // We can't be sure so we look into pids. + if (_psutil_pid_in_pids(pid) == 1) { + return hProcess; + } + else { + CloseHandle(hProcess); + NoSuchProcess(); + return NULL; + } + } + } + + CloseHandle(hProcess); + if (! psutil_assert_pid_not_exists( + pid, "GetExitCodeProcess() failed and PID exists")) { return NULL; } - return hProcess; + PyErr_SetFromWindowsErr(0); + return NULL; } |