diff options
author | Chris Robinson <[email protected]> | 2018-03-21 20:39:04 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-03-21 20:39:04 -0700 |
commit | 8f3d4965414e4e0963f1b1414135cb2a650ea289 (patch) | |
tree | 8696dfdcc268e4c0596e8c5e631d7ee8c88679ad /router/router.c | |
parent | 0a6c17c5440ce31b58bab6edb9d5fa26f70af93f (diff) |
Avoid duplicate path searches in the router
And avoid inadvertently increasing the priority of the system path over the
executable's path, or either of them over the current working directory.
Diffstat (limited to 'router/router.c')
-rw-r--r-- | router/router.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/router/router.c b/router/router.c index a0b554f4..bff73776 100644 --- a/router/router.c +++ b/router/router.c @@ -344,26 +344,47 @@ static int GetLoadedModuleDirectory(const WCHAR *name, WCHAR *moddir, DWORD leng void LoadDriverList(void) { - WCHAR path[MAX_PATH+1] = L""; + WCHAR dll_path[MAX_PATH+1] = L""; + WCHAR cwd_path[MAX_PATH+1] = L""; + WCHAR proc_path[MAX_PATH+1] = L""; + WCHAR sys_path[MAX_PATH+1] = L""; int len; - if(GetLoadedModuleDirectory(L"OpenAL32.dll", path, MAX_PATH)) - SearchDrivers(path); - - GetCurrentDirectoryW(MAX_PATH, path); - len = lstrlenW(path); - if(len > 0 && (path[len-1] == '\\' || path[len-1] == '/')) - path[len-1] = '\0'; - SearchDrivers(path); - - if(GetLoadedModuleDirectory(NULL, path, MAX_PATH)) - SearchDrivers(path); - - GetSystemDirectoryW(path, MAX_PATH); - len = lstrlenW(path); - if(len > 0 && (path[len-1] == '\\' || path[len-1] == '/')) - path[len-1] = '\0'; - SearchDrivers(path); + if(GetLoadedModuleDirectory(L"OpenAL32.dll", dll_path, MAX_PATH)) + TRACE("Got DLL path %ls\n", dll_path); + + GetCurrentDirectoryW(MAX_PATH, cwd_path); + len = lstrlenW(cwd_path); + if(len > 0 && (cwd_path[len-1] == '\\' || cwd_path[len-1] == '/')) + cwd_path[len-1] = '\0'; + TRACE("Got current working directory %ls\n", cwd_path); + + if(GetLoadedModuleDirectory(NULL, proc_path, MAX_PATH)) + TRACE("Got proc path %ls\n", proc_path); + + GetSystemDirectoryW(sys_path, MAX_PATH); + len = lstrlenW(sys_path); + if(len > 0 && (sys_path[len-1] == '\\' || sys_path[len-1] == '/')) + sys_path[len-1] = '\0'; + TRACE("Got system path %ls\n", sys_path); + + /* Don't search the DLL's path if it is the same as the current working + * directory, app's path, or system path (don't want to do duplicate + * searches, or increase the priority of the app or system path). + */ + if(dll_path[0] && + (!cwd_path[0] || wcscmp(dll_path, cwd_path) != 0) && + (!proc_path[0] || wcscmp(dll_path, proc_path) != 0) && + (!sys_path[0] || wcscmp(dll_path, sys_path) != 0)) + SearchDrivers(dll_path); + if(cwd_path[0] && + (!proc_path[0] || wcscmp(cwd_path, proc_path) != 0) && + (!sys_path[0] || wcscmp(cwd_path, sys_path) != 0)) + SearchDrivers(cwd_path); + if(proc_path[0] && (!sys_path[0] || wcscmp(proc_path, sys_path) != 0)) + SearchDrivers(proc_path); + if(sys_path[0]) + SearchDrivers(sys_path); } |