[vlc-devel] [PATCH] win32: make sure we only load Windows DLLs from the system directories

Rémi Denis-Courmont remi at remlab.net
Wed Mar 8 18:10:26 CET 2017


Le keskiviikkona 8. maaliskuuta 2017, 15.22.34 EET Steve Lhomme a écrit :
> ---
>  modules/audio_output/directsound.c               | 4 ++--
>  modules/codec/avcodec/d3d11va.c                  | 2 +-
>  modules/codec/avcodec/directx_va.c               | 2 +-
>  modules/codec/avcodec/dxva2.c                    | 2 +-
>  modules/codec/dmo/dmo.c                          | 4 ++--
>  modules/codec/mft.c                              | 2 +-
>  modules/gui/qt/components/simple_preferences.cpp | 2 +-
>  modules/text_renderer/freetype/fonts/dwrite.cpp  | 2 +-
>  modules/video_output/win32/common.c              | 2 +-
>  modules/video_output/win32/direct3d11.c          | 6 +++---
>  modules/video_output/win32/direct3d9.c           | 4 ++--
>  modules/video_output/win32/directdraw.c          | 4 ++--
>  modules/video_output/win32/win32touch.c          | 2 +-
>  src/network/udp.c                                | 2 +-
>  src/text/url.c                                   | 2 +-
>  15 files changed, 21 insertions(+), 21 deletions(-)
> 
> diff --git a/modules/audio_output/directsound.c
> b/modules/audio_output/directsound.c index 967971a353..59672c1473 100644
> --- a/modules/audio_output/directsound.c
> +++ b/modules/audio_output/directsound.c
> @@ -1043,7 +1043,7 @@ static int ReloadDirectXDevices( vlc_object_t *p_this,
> char const *psz_name,
> 
>      (void) psz_name;
> 
> -    HANDLE hdsound_dll = LoadLibrary(_T("DSOUND.DLL"));
> +    HANDLE hdsound_dll = LoadLibraryEx(_T("DSOUND.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if( hdsound_dll == NULL )
>      {
>          msg_Warn( p_this, "cannot open DSOUND.DLL" );
> @@ -1078,7 +1078,7 @@ static int Open(vlc_object_t *obj)
>  {
>      audio_output_t *aout = (audio_output_t *)obj;
> 
> -    HINSTANCE hdsound_dll = LoadLibrary(_T("DSOUND.DLL"));
> +    HINSTANCE hdsound_dll = LoadLibraryEx(_T("DSOUND.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (hdsound_dll == NULL)
>      {
>          msg_Warn(aout, "cannot open DSOUND.DLL");
> diff --git a/modules/codec/avcodec/d3d11va.c
> b/modules/codec/avcodec/d3d11va.c index 4ef9ac80ea..4614d7e234 100644
> --- a/modules/codec/avcodec/d3d11va.c
> +++ b/modules/codec/avcodec/d3d11va.c
> @@ -452,7 +452,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum
> PixelFormat pix_fmt, return VLC_ENOMEM;
> 
>  #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
> -    sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
> +    sys->dxgidebug_dll = LoadLibraryEx(TEXT("DXGIDEBUG.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); #endif
> 
>      dx_sys = &sys->dx_sys;
> diff --git a/modules/codec/avcodec/directx_va.c
> b/modules/codec/avcodec/directx_va.c index 1c26edcd6e..21f264e025 100644
> --- a/modules/codec/avcodec/directx_va.c
> +++ b/modules/codec/avcodec/directx_va.c
> @@ -451,7 +451,7 @@ int directx_va_Open(vlc_va_t *va, directx_sys_t *dx_sys,
> 
>      if (b_dll) {
>          /* Load dll*/
> -        dx_sys->hdecoder_dll = LoadLibrary(dx_sys->psz_decoder_dll);
> +        dx_sys->hdecoder_dll = LoadLibraryEx(dx_sys->psz_decoder_dll, NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (!dx_sys->hdecoder_dll) {
>              msg_Warn(va, "cannot load DirectX decoder DLL");
>              goto error;
> diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
> index d609ce07ae..0e451ed5ba 100644
> --- a/modules/codec/avcodec/dxva2.c
> +++ b/modules/codec/avcodec/dxva2.c
> @@ -350,7 +350,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum
> PixelFormat pix_fmt, return VLC_ENOMEM;
> 
>      /* Load dll*/
> -    sys->hd3d9_dll = LoadLibrary(TEXT("D3D9.DLL"));
> +    sys->hd3d9_dll = LoadLibraryEx(TEXT("D3D9.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (!sys->hd3d9_dll) {
>          msg_Warn(va, "cannot load d3d9.dll");
>          goto error;
> diff --git a/modules/codec/dmo/dmo.c b/modules/codec/dmo/dmo.c
> index ef40f3859f..fab32a9e50 100644
> --- a/modules/codec/dmo/dmo.c
> +++ b/modules/codec/dmo/dmo.c
> @@ -680,7 +680,7 @@ static int LoadDMO( vlc_object_t *p_this, HINSTANCE
> *p_hmsdmo_dll, }
> 
>      /* Load msdmo DLL */
> -    *p_hmsdmo_dll = LoadLibrary( TEXT( "msdmo.dll" ) );
> +    *p_hmsdmo_dll = LoadLibraryEx( TEXT( "msdmo.dll" ), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32 ); if( *p_hmsdmo_dll == NULL )
>      {
>          msg_Dbg( p_this, "failed loading msdmo.dll" );
> @@ -753,7 +753,7 @@ loader:
>      if( codecs_table[i_codec].i_fourcc == 0 )
>          return VLC_EGENERIC;    /* Can't happen */
> 
> -    *p_hmsdmo_dll = LoadLibrary( codecs_table[i_codec].psz_dll );
> +    *p_hmsdmo_dll = LoadLibraryEx( codecs_table[i_codec].psz_dll, NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32 ); if( *p_hmsdmo_dll == NULL )
>      {
>          msg_Dbg( p_this, "failed loading '"PRIs"'",
> diff --git a/modules/codec/mft.c b/modules/codec/mft.c
> index fbd85d4bdc..696ae7db6a 100644
> --- a/modules/codec/mft.c
> +++ b/modules/codec/mft.c
> @@ -1087,7 +1087,7 @@ static int FindMFT(decoder_t *p_dec)
>  static int LoadMFTLibrary(MFHandle *mf)
>  {
>  #if _WIN32_WINNT < _WIN32_WINNT_WIN7 || VLC_WINSTORE_APP
> -    mf->mfplat_dll = LoadLibrary(TEXT("mfplat.dll"));
> +    mf->mfplat_dll = LoadLibraryEx(TEXT("mfplat.dll"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (!mf->mfplat_dll)
>          return VLC_EGENERIC;
> 
> diff --git a/modules/gui/qt/components/simple_preferences.cpp
> b/modules/gui/qt/components/simple_preferences.cpp index
> b9e1d01a41..90b87216db 100644
> --- a/modules/gui/qt/components/simple_preferences.cpp
> +++ b/modules/gui/qt/components/simple_preferences.cpp
> @@ -609,7 +609,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf,
> QWidget *_parent, }
>              CONFIG_GENERIC( "avcodec-hw", StringList, ui.hwAccelLabel,
> hwAccelModule ); #ifdef _WIN32
> -            HINSTANCE hdxva2_dll = LoadLibrary(TEXT("DXVA2.DLL") );
> +            HINSTANCE hdxva2_dll = LoadLibraryEx(TEXT("DXVA2.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32 ); if( !hdxva2_dll )
>                  ui.hwAccelModule->setEnabled( false );
>              else
> diff --git a/modules/text_renderer/freetype/fonts/dwrite.cpp
> b/modules/text_renderer/freetype/fonts/dwrite.cpp index
> addc91a326..82e9f53d12 100644
> --- a/modules/text_renderer/freetype/fonts/dwrite.cpp
> +++ b/modules/text_renderer/freetype/fonts/dwrite.cpp
> @@ -113,7 +113,7 @@ extern "C" int InitDWrite( filter_t *p_filter )
>  #if VLC_WINSTORE_APP
>          p_dw_sys = new dw_sys_t( p_dw_dll );
>  #else
> -        p_dw_dll = LoadLibrary( TEXT( "Dwrite.dll" ) );
> +        p_dw_dll = LoadLibraryEx( TEXT( "Dwrite.dll" ), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32 ); if( p_dw_dll == NULL )
>              return VLC_EGENERIC;
> 
> diff --git a/modules/video_output/win32/common.c
> b/modules/video_output/win32/common.c index f2b97b88e3..e0d30a8b44 100644
> --- a/modules/video_output/win32/common.c
> +++ b/modules/video_output/win32/common.c
> @@ -122,7 +122,7 @@ int CommonInit(vout_display_t *vd)
>      DisableScreensaver (vd);
>  #endif
>  #if !defined(NDEBUG) && defined(HAVE_DXGIDEBUG_H)
> -    sys->dxgidebug_dll = LoadLibrary(TEXT("DXGIDEBUG.DLL"));
> +    sys->dxgidebug_dll = LoadLibraryEx(TEXT("DXGIDEBUG.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); #endif
> 
>      return VLC_SUCCESS;
> diff --git a/modules/video_output/win32/direct3d11.c
> b/modules/video_output/win32/direct3d11.c index e7c9185609..f1cfdd1a3f
> 100644
> --- a/modules/video_output/win32/direct3d11.c
> +++ b/modules/video_output/win32/direct3d11.c
> @@ -371,7 +371,7 @@ static int OpenHwnd(vout_display_t *vd)
>      if (!sys)
>          return VLC_ENOMEM;
> 
> -    sys->hd3d11_dll = LoadLibrary(TEXT("D3D11.DLL"));
> +    sys->hd3d11_dll = LoadLibraryEx(TEXT("D3D11.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (!sys->hd3d11_dll) {
>          msg_Warn(vd, "cannot load d3d11.dll, aborting");
>          return VLC_EGENERIC;
> @@ -1307,7 +1307,7 @@ static HINSTANCE Direct3D11LoadShaderLibrary(void)
>      for (int i = 47; i > 41; --i) {
>          TCHAR filename[19];
>          _sntprintf(filename, 19, TEXT("D3DCOMPILER_%d.dll"), i);
> -        instance = LoadLibrary(filename);
> +        instance = LoadLibraryEx(filename, NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (instance) break;
>      }
>      return instance;
> @@ -1328,7 +1328,7 @@ static int Direct3D11Open(vout_display_t *vd,
> video_format_t *fmt) HRESULT hr = S_OK;
> 
>  # if !defined(NDEBUG)
> -    HINSTANCE sdklayer_dll = LoadLibrary(TEXT("d3d11_1sdklayers.dll"));
> +    HINSTANCE sdklayer_dll = LoadLibraryEx(TEXT("d3d11_1sdklayers.dll"),
> NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if (sdklayer_dll) {
>          creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
>          FreeLibrary(sdklayer_dll);
> diff --git a/modules/video_output/win32/direct3d9.c
> b/modules/video_output/win32/direct3d9.c index f190e65147..a700a8c59d
> 100644
> --- a/modules/video_output/win32/direct3d9.c
> +++ b/modules/video_output/win32/direct3d9.c
> @@ -631,7 +631,7 @@ static HINSTANCE Direct3D9LoadShaderLibrary(void)
>      for (int i = 43; i > 23; --i) {
>          TCHAR filename[16];
>          _sntprintf(filename, 16, TEXT("D3dx9_%d.dll"), i);
> -        instance = LoadLibrary(filename);
> +        instance = LoadLibraryEx(filename, NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (instance)
>              break;
>      }
> @@ -645,7 +645,7 @@ static int Direct3D9Create(vout_display_t *vd)
>  {
>      vout_display_sys_t *sys = vd->sys;
> 
> -    sys->hd3d9_dll = LoadLibrary(TEXT("D3D9.DLL"));
> +    sys->hd3d9_dll = LoadLibraryEx(TEXT("D3D9.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (!sys->hd3d9_dll) {
>          msg_Warn(vd, "cannot load d3d9.dll, aborting");
>          return VLC_EGENERIC;
> diff --git a/modules/video_output/win32/directdraw.c
> b/modules/video_output/win32/directdraw.c index d3c59310e3..fdbd51dd14
> 100644
> --- a/modules/video_output/win32/directdraw.c
> +++ b/modules/video_output/win32/directdraw.c
> @@ -205,7 +205,7 @@ static int Open(vlc_object_t *object)
>          return VLC_ENOMEM;
> 
>      /* Load direct draw DLL */
> -    sys->hddraw_dll = LoadLibrary(_T("DDRAW.DLL"));
> +    sys->hddraw_dll = LoadLibraryEx(_T("DDRAW.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (!sys->hddraw_dll) {
>          msg_Warn(vd, "DirectXInitDDraw failed loading ddraw.dll");
>          free(sys);
> @@ -1494,7 +1494,7 @@ static int FindDevicesCallback(vlc_object_t *object,
> const char *name, ctx.count = 1;
> 
>      /* Load direct draw DLL */
> -    HINSTANCE hddraw_dll = LoadLibrary(_T("DDRAW.DLL"));
> +    HINSTANCE hddraw_dll = LoadLibraryEx(_T("DDRAW.DLL"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (hddraw_dll != NULL)
>      {
>          /* Enumerate displays */
> diff --git a/modules/video_output/win32/win32touch.c
> b/modules/video_output/win32/win32touch.c index 0e0846ae45..67ce0d7906
> 100644
> --- a/modules/video_output/win32/win32touch.c
> +++ b/modules/video_output/win32/win32touch.c
> @@ -206,7 +206,7 @@ BOOL InitGestures( HWND hwnd, win32_gesture_sys_t
> **pp_gesture ) return FALSE;
>      }
> 
> -    HINSTANCE h_user32_dll = LoadLibrary(TEXT("user32.dll"));
> +    HINSTANCE h_user32_dll = LoadLibraryEx(TEXT("user32.dll"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if( !h_user32_dll )
>      {
>          *pp_gesture = NULL;
> diff --git a/src/network/udp.c b/src/network/udp.c
> index d098fb1425..3467785bf1 100644
> --- a/src/network/udp.c
> +++ b/src/network/udp.c
> @@ -105,7 +105,7 @@ static int net_SetupDgramSocket (vlc_object_t *p_obj,
> int fd, * receive buffer if that isn't present
>       */
>  #if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
> -    HINSTANCE h_Network = LoadLibrary(TEXT("Windows.Networking.dll"));
> +    HINSTANCE h_Network = LoadLibraryEx(TEXT("Windows.Networking.dll"),
> NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); if( (h_Network == NULL) ||
>          (GetProcAddress( h_Network, "SetSocketMediaStreamingMode" ) == NULL
> ) ) {
> diff --git a/src/text/url.c b/src/text/url.c
> index 1b602b599e..d15f0a6660 100644
> --- a/src/text/url.c
> +++ b/src/text/url.c
> @@ -837,7 +837,7 @@ char *vlc_uri_fixup(const char *str)
>  #  define IDN_ALLOW_UNASSIGNED 0x01
>  static int IdnToAscii(DWORD flags, LPCWSTR str, int len, LPWSTR buf, int
> size) {
> -    HMODULE h = LoadLibrary(_T("Normaliz.dll"));
> +    HMODULE h = LoadLibraryEx(_T("Normaliz.dll"), NULL,
> LOAD_LIBRARY_SEARCH_SYSTEM32); if (h == NULL)
>      {
>          errno = ENOSYS;

Consider wrapping lines?

Also please upgrade _WIN32_WINNT to Vista and remove logically dead code 
before you apply this.

Otherwise looks OK.

-- 
雷米‧德尼-库尔蒙
https://www.remlab.net/



More information about the vlc-devel mailing list