[vlc-commits] Win32: modify the LoadLibrary PATHS used

Jean-Baptiste Kempf git at videolan.org
Mon Jul 4 00:00:34 CEST 2016


vlc/vlc-2.2 | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Fri Jul  1 13:26:19 2016 +0200| [c38d9521052fee1f9ec6406e2d7fd76b8154009a] | committer: Jean-Baptiste Kempf

Win32: modify the LoadLibrary PATHS used

We used to load system libraries without the full path, notably for
DirectX-related libraries. This is a bad idea if someone puts a
similarly-named DLL in the VLC folder, because they would be loaded.

Indeed, even if we don't load from CWD, we still load from the
application, which could be an issue, if you install a DLL next to
libvlccore.dll.

Therefore, on modern Windows systems, now LoadLibrary calls are
completely limited to SYSTEM32; except when loading vlc modules,
where they are limited to the application folder.

(cherry picked from commit c220ddc927d1a97f72a0c5bf86de56301e3483ad)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=c38d9521052fee1f9ec6406e2d7fd76b8154009a
---

 src/win32/plugin.c   |    4 +++-
 src/win32/specific.c |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/win32/plugin.c b/src/win32/plugin.c
index a9e0e6c..cd088a5 100644
--- a/src/win32/plugin.c
+++ b/src/win32/plugin.c
@@ -33,6 +33,8 @@
 #include <windows.h>
 #include <wchar.h>
 
+extern DWORD LoadLibraryFlags;
+
 static char *GetWindowsError( void )
 {
     wchar_t wmsg[256];
@@ -64,7 +66,7 @@ int module_Load( vlc_object_t *p_this, const char *psz_file,
     if (SetThreadErrorMode (SEM_FAILCRITICALERRORS, &mode) != 0)
 #endif
     {
-        handle = LoadLibraryW (wfile);
+        handle = LoadLibraryExW (wfile, NULL, LoadLibraryFlags );
 #if (_WIN32_WINNT >= 0x601) && !VLC_WINSTORE_APP
         SetThreadErrorMode (mode, NULL);
 #endif
diff --git a/src/win32/specific.c b/src/win32/specific.c
index fdcb9f4..fd1a21d 100644
--- a/src/win32/specific.c
+++ b/src/win32/specific.c
@@ -34,6 +34,7 @@
 #include <mmsystem.h>
 #include <winsock.h>
 
+DWORD LoadLibraryFlags = 0;
 
 static int system_InitWSA(int hi, int lo)
 {
@@ -60,6 +61,21 @@ void system_Init(void)
 
     if (system_InitWSA(2, 2) && system_InitWSA(1, 1))
         fputs("Error: cannot initialize Winsocks\n", stderr);
+
+#if !VLC_WINSTORE_APP
+    typedef BOOL (WINAPI *SetDefaultDllDirectoriesFunc)( DWORD DirectoryFlags);
+    SetDefaultDllDirectoriesFunc pf_SetDefDllDir = (SetDefaultDllDirectoriesFunc)
+        GetProcAddress( GetModuleHandleW(TEXT("kernel32.dll")), "SetDefaultDllDirectories");
+
+    if( pf_SetDefDllDir ) {
+        pf_SetDefDllDir( LOAD_LIBRARY_SEARCH_SYSTEM32 );
+        LoadLibraryFlags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
+                           LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
+    }
+#else
+    LoadLibraryFlags = LOAD_LIBRARY_SEARCH_APPLICATION_DIR |
+                       LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
+#endif
 }
 
 /*****************************************************************************



More information about the vlc-commits mailing list