diff options
author | James Ross-Gowan <rossymiles@gmail.com> | 2014-01-07 23:26:26 +1100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-01-27 10:04:29 +0100 |
commit | d26ee98fa61872164aacd647ae8416626e802984 (patch) | |
tree | d84f1d48036cbc6147ffaf7e93a4d415e32ff675 /player | |
parent | 4c83a93617528072fbdda9fc7e6159bc8a5769fc (diff) | |
download | mpv-d26ee98fa61872164aacd647ae8416626e802984.tar.bz2 mpv-d26ee98fa61872164aacd647ae8416626e802984.tar.xz |
w32: use safe DLL search paths everywhere
Windows applications that use LoadLibrary are vulnerable to DLL
preloading attacks if a malicious DLL with the same name as a system DLL
is placed in the current directory. mpv had some code to avoid this in
ao_wasapi.c. This commit just moves it to main.c, since there's no
reason it can't be used process-wide.
This change can affect how plugins are loaded in AviSynth, but it
shouldn't be a problem since MPC-HC also does this and it's a very
popular AviSynth client.
Diffstat (limited to 'player')
-rw-r--r-- | player/main.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/player/main.c b/player/main.c index e46b3d2b0a..d1c1017414 100644 --- a/player/main.c +++ b/player/main.c @@ -79,6 +79,14 @@ #if defined(__MINGW32__) || defined(__CYGWIN__) #include <windows.h> + +#ifndef BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE +#define BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE (0x0001) +#endif + +#ifndef BASE_SEARCH_PATH_PERMANENT +#define BASE_SEARCH_PATH_PERMANENT (0x8000) +#endif #endif const char mp_help_text[] = @@ -265,6 +273,19 @@ static void osdep_preinit(int *p_argc, char ***p_argv) // Enable heap corruption detection HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); + + HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); + WINBOOL (WINAPI *pSetDllDirectory)(LPCWSTR lpPathName) = + (WINBOOL (WINAPI *)(LPCWSTR))GetProcAddress(kernel32, "SetDllDirectoryW"); + WINBOOL (WINAPI *pSetSearchPathMode)(DWORD Flags) = + (WINBOOL (WINAPI *)(DWORD))GetProcAddress(kernel32, "SetSearchPathMode"); + + // Always use safe search paths for DLLs and other files, ie. never use the + // current directory + if (pSetSearchPathMode) + pSetDllDirectory(L""); + if (pSetSearchPathMode) + pSetSearchPathMode(BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE); #endif terminal_init(); |