Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH v2] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll
@ 2022-05-25 22:02 Martin Storsjö
  2022-05-27 22:16 ` Martin Storsjö
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Storsjö @ 2022-05-25 22:02 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Martin Storsjö, trystan.mata, timo

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(-)

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);
-- 
2.25.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-05-27 22:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 22:02 [FFmpeg-devel] [PATCH v2] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll Martin Storsjö
2022-05-27 22:16 ` Martin Storsjö

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git