osdep/io: expand path before LoadLibrary

Fixes compatibility with loading scripts from relative config paths.

Fixes #13212
This commit is contained in:
Kacper Michajłow 2024-01-21 18:27:04 +01:00 committed by Dudemanguy
parent 6ae5ff26b0
commit 52cabca4e5
1 changed files with 17 additions and 3 deletions

View File

@ -738,9 +738,23 @@ static void mp_dl_init(void)
void *mp_dlopen(const char *filename, int flag)
{
wchar_t *wfilename = mp_from_utf8(NULL, filename);
HMODULE lib = LoadLibraryW(wfilename);
talloc_free(wfilename);
HMODULE lib = NULL;
void *ta_ctx = talloc_new(NULL);
wchar_t *wfilename = mp_from_utf8(ta_ctx, filename);
DWORD len = GetFullPathNameW(wfilename, 0, NULL, NULL);
if (!len)
goto err;
wchar_t *path = talloc_array(ta_ctx, wchar_t, len);
len = GetFullPathNameW(wfilename, len, path, NULL);
if (!len)
goto err;
lib = LoadLibraryW(path);
err:
talloc_free(ta_ctx);
mp_dl_result.errcode = GetLastError();
return (void *)lib;
}