diff mbox series

[FFmpeg-devel,v2] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll

Message ID 20220525220233.3813609-1-martin@martin.st
State Accepted
Commit 9fba0b8a8c754a012fc74c90ffb7c26a56be8ca0
Headers show
Series [FFmpeg-devel,v2] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Martin Storsjö May 25, 2022, 10:02 p.m. UTC
The dlopen wrapper contains code to make loading libraries safer,
to avoid loading a potentially malicious DLL with the same name.

Signed-off-by: Martin Storsjö <martin@martin.st>
---
v2: Use dlsym too, for consistency.
---
 libavcodec/mfenc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Martin Storsjö May 27, 2022, 10:16 p.m. UTC | #1
On Thu, 26 May 2022, Martin Storsjö wrote:

> The dlopen wrapper contains code to make loading libraries safer,
> to avoid loading a potentially malicious DLL with the same name.
>
> Signed-off-by: Martin Storsjö <martin@martin.st>
> ---
> v2: Use dlsym too, for consistency.
> ---
> libavcodec/mfenc.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)

Pushed.

// Martin
diff mbox series

Patch

diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 17d0ec60bd..13ed7b3e11 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -29,6 +29,7 @@ 
 #include "libavutil/time.h"
 #include "codec_internal.h"
 #include "internal.h"
+#include "compat/w32dlfcn.h"
 
 typedef struct MFContext {
     AVClass *av_class;
@@ -1131,7 +1132,7 @@  static int mf_init_encoder(AVCodecContext *avctx)
 
 #if !HAVE_UWP
 #define LOAD_MF_FUNCTION(context, func_name) \
-    context->functions.func_name = (void *)GetProcAddress(context->library, #func_name); \
+    context->functions.func_name = (void *)dlsym(context->library, #func_name); \
     if (!context->functions.func_name) { \
         av_log(context, AV_LOG_ERROR, "DLL mfplat.dll failed to find function "\
            #func_name "\n"); \
@@ -1158,7 +1159,7 @@  static int mf_load_library(AVCodecContext *avctx)
     MFContext *c = avctx->priv_data;
 
 #if !HAVE_UWP
-    c->library = LoadLibraryA("mfplat.dll");
+    c->library = dlopen("mfplat.dll", 0);
 
     if (!c->library) {
         av_log(c, AV_LOG_ERROR, "DLL mfplat.dll failed to open\n");
@@ -1191,7 +1192,7 @@  static int mf_close(AVCodecContext *avctx)
     if (c->library)
         ff_free_mf(&c->functions, &c->mft);
 
-    FreeLibrary(c->library);
+    dlclose(c->library);
     c->library = NULL;
 #else
     ff_free_mf(&c->functions, &c->mft);