Skip to content

Commit 936391a

Browse files
nurmukhametovaneshlya
authored andcommitted
ispcrt: removes CWD from the search path for LoadLibraryEx
1 parent d3f561c commit 936391a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

ispcrt/detail/cpu/CPUDevice.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ struct Module : public ispcrt::base::Module {
136136
#endif
137137
void *lib = nullptr;
138138
#if defined _WIN32
139-
lib = LoadLibrary((m_file + ext).c_str());
139+
// Removes CWD from the search path to reduce the risk of DLL injection.
140+
SetDllDirectory("");
141+
lib = LoadLibraryEx((m_file + ext).c_str(), NULL, 0);
140142
#else
141143
lib = dlopen(("lib" + m_file + ext).c_str(), RTLD_LAZY | RTLD_LOCAL);
142144
#endif

ispcrt/ispcrt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ static OBJECT_T &referenceFromHandle(HANDLE_T handle) {
129129
// OS agnostic function to dynamically load a shared library.
130130
void *dyn_load_lib(const char *name, const char *name_major_version, const char *name_full_version) {
131131
#if defined(_WIN32) || defined(_WIN64)
132-
return LoadLibrary(name);
132+
// Removes CWD from the search path to reduce the risk of DLL injection.
133+
SetDllDirectory("");
134+
return LoadLibraryEx(name, NULL, 0);
133135
#else
134136
// Try to load a device library starting from the most specific name down to more general one.
135137
void *handle = dlopen(name_full_version, RTLD_NOW | RTLD_LOCAL);

0 commit comments

Comments
 (0)