summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-14 13:02:55 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-14 13:02:55 -0800
commitefaa9e0169e790310e19cea1c4d8389395387c0d (patch)
tree51b81594b2ffc073e19bdfb7c8ef8ff915d916bd
parentbc0168ad4a5467ab369f120e646fda811175b210 (diff)
downloadpsutil-efaa9e0169e790310e19cea1c4d8389395387c0d.tar.gz
fix #1662: QueryFullProcessImageNameW may fail with error code = 0 (Win API bug?)
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_psutil_windows.c6
2 files changed, 6 insertions, 1 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index f51553a0..4ca36b81 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -21,6 +21,7 @@ XXXX-XX-XX
- 1656_: [Windows] Process.memory_full_info() raises AccessDenied even for the
current user and os.getpid().
- 1660_: [Windows] Process.open_files() complete rewrite + check of errors.
+- 1662_: [Windows] process exe() may raise WinError 0.
5.6.7
=====
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 9985e1d3..510bde8a 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -463,7 +463,11 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
memset(exe, 0, MAX_PATH);
if (QueryFullProcessImageNameW(hProcess, 0, exe, &size) == 0) {
- PyErr_SetFromOSErrnoWithSyscall("QueryFullProcessImageNameW");
+ // https://github.com/giampaolo/psutil/issues/1662
+ if (GetLastError() == 0)
+ AccessDenied("QueryFullProcessImageNameW (forced EPERM)");
+ else
+ PyErr_SetFromOSErrnoWithSyscall("QueryFullProcessImageNameW");
CloseHandle(hProcess);
return NULL;
}