From 8801dbef0676e0866d22ef7ebda7dce44e6ab675 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Wed, 27 Nov 2024 01:36:15 +0100 Subject: [PATCH] libobs: Avoid calling SetDllDirectory when looking for dependent DLLs Using the full path and appropriate LoadLibraryEx flags is safer as it gives us more control over the search paths. --- libobs/util/platform-windows.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/libobs/util/platform-windows.c b/libobs/util/platform-windows.c index bd40a2c51..df4efb784 100644 --- a/libobs/util/platform-windows.c +++ b/libobs/util/platform-windows.c @@ -83,19 +83,21 @@ void *os_dlopen(const char *path) * dynamically loaded libraries on windows to search for dependent * libraries that are within the library's own directory */ wpath_slash = wcsrchr(wpath, L'/'); + if (wpath_slash) { - *wpath_slash = 0; - SetDllDirectoryW(wpath); - *wpath_slash = L'/'; + wchar_t fullpath[MAX_PATH]; + + /* FIXME: this should use the OBS install dir as a base and not rely on the current directory */ + if (GetFullPathNameW(wpath, MAX_PATH, fullpath, NULL)) { + h_library = LoadLibraryExW(fullpath, NULL, + LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + } + } else { + h_library = LoadLibraryExW(wpath, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); } - h_library = LoadLibraryW(wpath); - bfree(wpath); - if (wpath_slash) - SetDllDirectoryW(NULL); - if (!h_library) { DWORD error = GetLastError();