Skip to content

Commit a1b9593

Browse files
authored
Use safe DLL loading (avoid current directory) (#1293)
1 parent 737adea commit a1b9593

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

strings/base_activation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace winrt::impl
3939

4040
if (hr == impl::error_not_initialized)
4141
{
42-
auto usage = reinterpret_cast<int32_t(__stdcall*)(void** cookie) noexcept>(WINRT_IMPL_GetProcAddress(WINRT_IMPL_LoadLibraryW(L"combase.dll"), "CoIncrementMTAUsage"));
42+
auto usage = reinterpret_cast<int32_t(__stdcall*)(void** cookie) noexcept>(WINRT_IMPL_GetProcAddress(load_library(L"combase.dll"), "CoIncrementMTAUsage"));
4343

4444
if (!usage)
4545
{
@@ -66,7 +66,7 @@ namespace winrt::impl
6666
{
6767
path.resize(count);
6868
path += L".dll";
69-
library_handle library(WINRT_IMPL_LoadLibraryW(path.c_str()));
69+
library_handle library(load_library(path.c_str()));
7070
path.resize(path.size() - 4);
7171

7272
if (!library)

strings/base_agile_ref.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ namespace winrt::impl
126126
atomic_ref_count m_references{ 1 };
127127
};
128128

129+
inline void* load_library(wchar_t const* library) noexcept
130+
{
131+
return WINRT_IMPL_LoadLibraryExW(library, nullptr, 0x00001000 /* LOAD_LIBRARY_SEARCH_DEFAULT_DIRS */);
132+
}
133+
129134
template <typename F, typename L>
130135
void load_runtime_function(wchar_t const* library, char const* name, F& result, L fallback) noexcept
131136
{
@@ -134,7 +139,7 @@ namespace winrt::impl
134139
return;
135140
}
136141

137-
result = reinterpret_cast<F>(WINRT_IMPL_GetProcAddress(WINRT_IMPL_LoadLibraryW(library), name));
142+
result = reinterpret_cast<F>(WINRT_IMPL_GetProcAddress(load_library(library), name));
138143

139144
if (result)
140145
{

strings/base_extern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ __declspec(selectany) int32_t(__stdcall* winrt_activation_handler)(void* classId
2424

2525
extern "C"
2626
{
27-
void* __stdcall WINRT_IMPL_LoadLibraryW(wchar_t const* name) noexcept WINRT_IMPL_LINK(LoadLibraryW, 4);
27+
void* __stdcall WINRT_IMPL_LoadLibraryExW(wchar_t const* name, void* unused, uint32_t flags) noexcept WINRT_IMPL_LINK(LoadLibraryExW, 12);
2828
int32_t __stdcall WINRT_IMPL_FreeLibrary(void* library) noexcept WINRT_IMPL_LINK(FreeLibrary, 4);
2929
void* __stdcall WINRT_IMPL_GetProcAddress(void* library, char const* name) noexcept WINRT_IMPL_LINK(GetProcAddress, 8);
3030

0 commit comments

Comments
 (0)