* [FFmpeg-devel] [PATCH] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll
@ 2022-05-25 21:35 Martin Storsjö
2022-05-25 21:42 ` Timo Rothenpieler
0 siblings, 1 reply; 3+ messages in thread
From: Martin Storsjö @ 2022-05-25 21:35 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>
---
libavcodec/mfenc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index 17d0ec60bd..ab0b6b4145 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;
@@ -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] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll
2022-05-25 21:35 [FFmpeg-devel] [PATCH] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll Martin Storsjö
@ 2022-05-25 21:42 ` Timo Rothenpieler
2022-05-25 22:01 ` Martin Storsjö
0 siblings, 1 reply; 3+ messages in thread
From: Timo Rothenpieler @ 2022-05-25 21:42 UTC (permalink / raw)
To: FFmpeg development discussions and patches, Martin Storsjö
Cc: trystan.mata
On 25/05/2022 23:35, 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>
> ---
> libavcodec/mfenc.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
> index 17d0ec60bd..ab0b6b4145 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;
> @@ -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);
Very much a nit, given this code only ever runs on Windows, and dlsym is
just a literal define to GetProcAddress, but mixing
dlopen()+GetProcddress() like that looks kinda weird :D
_______________________________________________
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] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll
2022-05-25 21:42 ` Timo Rothenpieler
@ 2022-05-25 22:01 ` Martin Storsjö
0 siblings, 0 replies; 3+ messages in thread
From: Martin Storsjö @ 2022-05-25 22:01 UTC (permalink / raw)
To: Timo Rothenpieler
Cc: trystan.mata, FFmpeg development discussions and patches
On Wed, 25 May 2022, Timo Rothenpieler wrote:
> On 25/05/2022 23:35, 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>
>> ---
>> libavcodec/mfenc.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
>> index 17d0ec60bd..ab0b6b4145 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;
>> @@ -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);
>
> Very much a nit, given this code only ever runs on Windows, and dlsym is
> just a literal define to GetProcAddress, but mixing
> dlopen()+GetProcddress() like that looks kinda weird :D
Ah, yes, it's indeed best to keep it consistent.
// Martin
_______________________________________________
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] 3+ messages in thread
end of thread, other threads:[~2022-05-25 22:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 21:35 [FFmpeg-devel] [PATCH] mfenc: Use dlopen instead of LoadLibrary for loading mfplat.dll Martin Storsjö
2022-05-25 21:42 ` Timo Rothenpieler
2022-05-25 22:01 ` 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