Normalize directory separators before calling LoadLibrary (#23776)
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>
Sun, 7 Apr 2019 00:47:13 +0000 (17:47 -0700)
committerAaron Robinson <arobins@microsoft.com>
Sun, 7 Apr 2019 00:47:13 +0000 (17:47 -0700)
* Normalize directory separators when loading native library via ALC.LoadUnmanagedDllFromPath

src/utilcode/longfilepathwrappers.cpp

index af77a01..bfeb96d 100644 (file)
@@ -30,6 +30,10 @@ public:
         static BOOL IsDevice(SString & path);
 
         static HRESULT NormalizePath(SString& path);
+
+#ifndef FEATURE_PAL
+        static void NormalizeDirectorySeparators(SString& path);
+#endif
 };
 
 HMODULE
@@ -59,6 +63,7 @@ LoadLibraryExWrapper(
 #ifndef FEATURE_PAL
             //Adding the assert to ensure relative paths which are not just filenames are not used for LoadLibrary Calls
             _ASSERTE(!LongFile::IsPathNotFullyQualified(path) || !LongFile::ContainsDirectorySeparator(path));
+            LongFile::NormalizeDirectorySeparators(path);
 #endif //FEATURE_PAL
 
             ret = LoadLibraryExW(path.GetUnicode(), hFile, dwFlags);
@@ -1173,6 +1178,17 @@ const WCHAR* LongFile::DevicePathPrefix = W("\\\\.\\");
 const WCHAR* LongFile::UNCExtendedPathPrefix = W("\\\\?\\UNC\\");
 const WCHAR* LongFile::UNCPathPrefix = UNCPATHPREFIX;
 
+void LongFile::NormalizeDirectorySeparators(SString& path)
+{
+    for(SString::Iterator i = path.Begin(); i < path.End(); ++i)
+    {
+        if (*i == AltDirectorySeparatorChar)
+        {
+            path.Replace(i, DirectorySeparatorChar);
+        }
+    }
+}
+
 BOOL LongFile::IsExtended(SString & path)
 {
     return path.BeginsWith(ExtendedPrefix);