From ef54649286408053c0620d366dc06ead7d7cae5a Mon Sep 17 00:00:00 2001 From: Lomanic Date: Sat, 18 Aug 2018 22:47:25 +0200 Subject: [PATCH] [windows] Use windows.NewLazySystemDLL to (possibly) prevent DLL hijacking Might be useless because of https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-search-order#search-order-for-desktop-applications but better be safe than sorry. Ref: https://github.com/shirou/gopsutil/issues/570#issuecomment-413951653 --- internal/common/common_windows.go | 8 ++++---- net/net_windows.go | 2 +- process/process_windows.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/common/common_windows.go b/internal/common/common_windows.go index b02c5cf..0997c9b 100644 --- a/internal/common/common_windows.go +++ b/internal/common/common_windows.go @@ -47,10 +47,10 @@ const ( ) var ( - Modkernel32 = windows.NewLazyDLL("kernel32.dll") - ModNt = windows.NewLazyDLL("ntdll.dll") - ModPdh = windows.NewLazyDLL("pdh.dll") - ModPsapi = windows.NewLazyDLL("psapi.dll") + Modkernel32 = windows.NewLazySystemDLL("kernel32.dll") + ModNt = windows.NewLazySystemDLL("ntdll.dll") + ModPdh = windows.NewLazySystemDLL("pdh.dll") + ModPsapi = windows.NewLazySystemDLL("psapi.dll") ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes") ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation") diff --git a/net/net_windows.go b/net/net_windows.go index 7fff20e..944b1e1 100644 --- a/net/net_windows.go +++ b/net/net_windows.go @@ -13,7 +13,7 @@ import ( ) var ( - modiphlpapi = windows.NewLazyDLL("iphlpapi.dll") + modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll") procGetExtendedTCPTable = modiphlpapi.NewProc("GetExtendedTcpTable") procGetExtendedUDPTable = modiphlpapi.NewProc("GetExtendedUdpTable") ) diff --git a/process/process_windows.go b/process/process_windows.go index 613b2b4..199b9b4 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -25,7 +25,7 @@ const ( ) var ( - modpsapi = windows.NewLazyDLL("psapi.dll") + modpsapi = windows.NewLazySystemDLL("psapi.dll") procGetProcessMemoryInfo = modpsapi.NewProc("GetProcessMemoryInfo") )