From b1cef469a3d6ae4a9f0ca159b6a3f93d92ff585a Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Tue, 7 Jan 2020 18:02:12 -0800 Subject: check file type before duplicating the handle --- psutil/arch/windows/process_handles.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/psutil/arch/windows/process_handles.c b/psutil/arch/windows/process_handles.c index 1872c572..16d04aee 100644 --- a/psutil/arch/windows/process_handles.c +++ b/psutil/arch/windows/process_handles.c @@ -181,6 +181,10 @@ psutil_get_open_files(DWORD dwPid, HANDLE hProcess) { if ((ULONG_PTR)hHandle->UniqueProcessId != dwPid) goto loop_cleanup; + // not a file + if (GetFileType((HANDLE)hHandle->HandleValue) != FILE_TYPE_DISK) + goto loop_cleanup; + if (!DuplicateHandle(hProcess, (HANDLE)hHandle->HandleValue, GetCurrentProcess(), -- cgit v1.2.1