summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-17 08:06:38 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-02-17 08:06:38 -0800
commit27233f96abc59470fa587e42afea9f4b79758330 (patch)
treef032f7961d748edbb1dc18c9d5b02217e60c850c
parent1c3287754f7b87708c3b81e72d1ab4f7f423e9ea (diff)
downloadpsutil-27233f96abc59470fa587e42afea9f4b79758330.tar.gz
#1394 / win / exe: use QueryFullProcessImageNameW to get the exe()
-rw-r--r--HISTORY.rst11
-rw-r--r--psutil/__init__.py2
-rw-r--r--psutil/_psutil_windows.c12
-rw-r--r--psutil/_pswindows.py12
4 files changed, 19 insertions, 18 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index ebac8db7..b1eb8ea4 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,5 +1,16 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*
+5.5.2
+=====
+
+XXXX-XX-XX
+
+**Bug fixes**
+
+- 1394_: [Windows] Process name() and exe() may erronously return "Registry".
+ QueryFullProcessImageNameW is now used instead of GetProcessImageFileNameW
+ in order to prevent that.
+
5.5.1
=====
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 9e7d3d02..241dc5f9 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -215,7 +215,7 @@ __all__ = [
]
__all__.extend(_psplatform.__extra__all__)
__author__ = "Giampaolo Rodola'"
-__version__ = "5.5.1"
+__version__ = "5.5.2"
version_info = tuple([int(num) for num in __version__.split('.')])
AF_LINK = _psplatform.AF_LINK
POWER_TIME_UNLIMITED = _common.POWER_TIME_UNLIMITED
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index eb35c5f7..7c94b816 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -763,6 +763,7 @@ static PyObject *
psutil_proc_exe(PyObject *self, PyObject *args) {
long pid;
HANDLE hProcess;
+ PDWORD size = MAX_PATH;
wchar_t exe[MAX_PATH];
if (! PyArg_ParseTuple(args, "l", &pid))
@@ -770,12 +771,11 @@ psutil_proc_exe(PyObject *self, PyObject *args) {
hProcess = psutil_handle_from_pid(pid, PROCESS_QUERY_LIMITED_INFORMATION);
if (NULL == hProcess)
return NULL;
- if (GetProcessImageFileNameW(hProcess, exe, MAX_PATH) == 0) {
- // https://github.com/giampaolo/psutil/issues/1394
- if (GetLastError() == 0)
- PyErr_SetFromWindowsErr(ERROR_ACCESS_DENIED);
- else
- PyErr_SetFromWindowsErr(0);
+ // before this was using GetProcessImageFileNameW see:
+ // https://github.com/giampaolo/psutil/issues/1394
+ memset(exe, 0, MAX_PATH);
+ if (QueryFullProcessImageNameW(hProcess, 0, exe, &size) == 0) {
+ PyErr_SetFromWindowsErr(0);
CloseHandle(hProcess);
return NULL;
}
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index e66febe0..66fb3c50 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -694,17 +694,7 @@ class Process(object):
@wrap_exceptions
def exe(self):
- # Note: os.path.exists(path) may return False even if the file
- # is there, see:
- # http://stackoverflow.com/questions/3112546/os-path-exists-lies
-
- # see https://github.com/giampaolo/psutil/issues/414
- # see https://github.com/giampaolo/psutil/issues/528
- if self.pid in (0, 4):
- raise AccessDenied(self.pid, self._name)
- exe = cext.proc_exe(self.pid)
- exe = convert_dos_path(exe)
- return py2_strencode(exe)
+ return cext.proc_exe(self.pid)
@wrap_exceptions
def cmdline(self):