From d64c300522ffa830e061adeb81e75255b3f955ac Mon Sep 17 00:00:00 2001 From: Pascal Quantin Date: Wed, 18 Oct 2017 10:11:56 +0200 Subject: Do not add Npcap path if npf.sys service is found Otherwise you can end with 2 Packet.dll (the one from WinPcap and the one from Npcap) being loaded at the same time, which can create incompatibilities. Bug: 14134 Change-Id: Ia06066fd54b60296e55dbfce6c6f2ddd99367479 Reviewed-on: https://code.wireshark.org/review/23969 Petri-Dish: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Pascal Quantin Reviewed-by: Anders Broman --- wsutil/file_util.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/wsutil/file_util.c b/wsutil/file_util.c index abd4ccab03..72ed16d813 100644 --- a/wsutil/file_util.c +++ b/wsutil/file_util.c @@ -504,10 +504,11 @@ init_dll_load_paths() gboolean ws_init_dll_search_path() { - gboolean dll_dir_set = FALSE; + gboolean dll_dir_set = FALSE, npf_found = FALSE; wchar_t *program_path_w; wchar_t npcap_path_w[MAX_PATH]; unsigned int retval; + SC_HANDLE h_scm; typedef BOOL (WINAPI *SetDllDirectoryHandler)(LPCTSTR); SetDllDirectoryHandler PSetDllDirectory; @@ -516,10 +517,22 @@ ws_init_dll_search_path() if (PSetDllDirectory) { dll_dir_set = PSetDllDirectory(_T("")); if (dll_dir_set) { - retval = GetSystemDirectoryW(npcap_path_w, MAX_PATH); - if (0 < retval && retval <= MAX_PATH) { - wcscat_s(npcap_path_w, MAX_PATH, L"\\Npcap"); - dll_dir_set = PSetDllDirectory(npcap_path_w); + /* Do not systematically add Npcap path as long as we favor WinPcap over Npcap. */ + h_scm = OpenSCManager(NULL, NULL, 0); + if (h_scm) { + if (OpenService(h_scm, _T("npf"), SC_MANAGER_CONNECT|SERVICE_QUERY_STATUS)) { + npf_found = TRUE; + } + CloseServiceHandle(h_scm); + } + if (!npf_found) { + /* npf service was not found, so WinPcap is not (properly) installed. + Add Npcap folder to libraries search path. */ + retval = GetSystemDirectoryW(npcap_path_w, MAX_PATH); + if (0 < retval && retval <= MAX_PATH) { + wcscat_s(npcap_path_w, MAX_PATH, L"\\Npcap"); + dll_dir_set = PSetDllDirectory(npcap_path_w); + } } } } -- cgit v1.2.3