[llvm] [Windows] Avoid loading shared system libraries from user directory (PR #90520)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 30 05:13:21 PDT 2024
================
@@ -44,8 +44,24 @@ InitLLVM::InitLLVM(int &Argc, const char **&Argv,
Initialized = true;
#endif
#ifdef _WIN32
- // Avoid searching the directory from which the application is loaded.
- SetDllDirectoryA("");
+ // Avoid searching user directories for shared libraries:
+ // Avoid searching the current directory:
+ (void)SetDllDirectoryA("");
+ wchar_t CurrentPath[MAX_PATH];
+ (void)GetCurrentDirectory(MAX_PATH, CurrentPath);
+ // Avoid searching the directory from which the application is loaded:
+ wchar_t Appname[MAX_PATH];
+ (void)GetModuleFileName(NULL, Appname, MAX_PATH);
+ std::array<wchar_t, MAX_PATH> AN;
+ std::copy(std::begin(Appname), std::end(Appname), std::begin(AN));
+ std::string LP{AN.begin(), AN.end()};
+ LP = LP.substr(0, LP.rfind('\\'));
+ auto Path = std::wstring(LP.begin(), LP.end());
+ auto LoadPath = Path.c_str();
----------------
arsenm wrote:
No auto. Also std::wstring Path(begin, end)?
https://github.com/llvm/llvm-project/pull/90520
More information about the llvm-commits
mailing list