Skip to content

Commit 5df8e75

Browse files
authored
Remove FILEDosToUnixPathA conversion (#78995)
* Remove FILEDosToUnixPathA conversion All file paths passed to the coreclr PAL are processed by this function to convert backslash characters to forward ones. This is causing problems when users have directories with names containing backslashes. Such problems were recently reported by people. This change removes the `FILEDosToUnixPathA` and fixes one PAL test and one coreclr test that was passing backslash separated paths. * Remove checks for `\` on Unix and some conversions * Update runtime to use platform specific directory separator * Revert changes at few places and remove some code for Unix * Fix Bundle_Extraction_To_Relative_Path_Succeeds host test Exclude the `foo\\bar` case for non-Windows.
1 parent 09613f3 commit 5df8e75

File tree

47 files changed

+273
-762
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+273
-762
lines changed

src/coreclr/debug/daccess/request.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ ClrDataAccess::GetMethodDescName(CLRDATA_ADDRESS methodDesc, unsigned int count,
13341334
nChars > 0 && nChars <= ARRAY_SIZE(path))
13351335
{
13361336
WCHAR* pFile = path + nChars - 1;
1337-
while ((pFile >= path) && (*pFile != W('\\')))
1337+
while ((pFile >= path) && (*pFile != DIRECTORY_SEPARATOR_CHAR_W))
13381338
{
13391339
pFile--;
13401340
}

src/coreclr/ildasm/dis.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,10 @@ BOOL Disassemble(IMDInternalImport *pImport, BYTE *ILHeader, void *GUICookie, md
11151115
pFile = NULL;
11161116
if(fopen_s(&pFile,szFileName,"rt") != 0)
11171117
{
1118-
char* pch = strrchr(szFileName,'\\');
1118+
char* pch = strrchr(szFileName, DIRECTORY_SEPARATOR_CHAR_A);
1119+
#ifdef HOST_WINDOWS
11191120
if(pch == NULL) pch = strrchr(szFileName,':');
1121+
#endif
11201122
pFile = NULL;
11211123
if(pch) fopen_s(&pFile,pch+1,"rt");
11221124
}

src/coreclr/ildasm/dman.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,10 @@ void DumpManifestResources(void* GUICookie)
782782
static WCHAR wzFileName[2048];
783783

784784
WszMultiByteToWideChar(CP_UTF8,0,g_szOutputFile,-1,wzFileName,2048);
785-
wzName = wcsrchr(wzFileName,'\\');
785+
wzName = wcsrchr(wzFileName,DIRECTORY_SEPARATOR_CHAR_W);
786+
#ifdef HOST_WINDOWS
786787
if(wzName == NULL) wzName = wcsrchr(wzFileName,':');
788+
#endif
787789
if (wzName == NULL) wzName = wzFileName;
788790
else wzName++;
789791

src/coreclr/inc/longfilepathwrappers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#define _WIN_PATH_APIS_WRAPPER_
66
class SString;
77

8+
#ifdef HOST_WINDOWS
9+
810
HMODULE
911
LoadLibraryExWrapper(
1012
_In_ LPCWSTR lpLibFileName,
@@ -35,7 +37,6 @@ GetFileAttributesExWrapper(
3537
_Out_writes_bytes_(sizeof(WIN32_FILE_ATTRIBUTE_DATA)) LPVOID lpFileInformation
3638
);
3739

38-
#ifndef HOST_UNIX
3940
BOOL
4041
CopyFileExWrapper(
4142
_In_ LPCWSTR lpExistingFileName,
@@ -46,7 +47,7 @@ CopyFileExWrapper(
4647
_Inout_opt_ LPBOOL pbCancel,
4748
_In_ DWORD dwCopyFlags
4849
);
49-
#endif //HOST_UNIX
50+
#endif //HOST_WINDOWS
5051

5152
DWORD
5253
SearchPathWrapper(

src/coreclr/inc/nsutilpriv.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ void MakeNestedTypeName( // throws on out of memory
208208
#define ASSEMBLY_SEPARATOR_STR ", "
209209
#define ASSEMBLY_SEPARATOR_WSTR W(", ")
210210
#define ASSEMBLY_SEPARATOR_LEN 2
211-
#define BACKSLASH_CHAR '\\'
212-
#define BACKSLASH_WCHAR W('\\')
213211
#define NESTED_SEPARATOR_CHAR '+'
214212
#define NESTED_SEPARATOR_WCHAR W('+')
215213
#define NESTED_SEPARATOR_STR "+"

src/coreclr/inc/winwrap.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,17 @@
189189

190190
//File and Directory Functions which need special handling for LongFile Names
191191
//Note only the functions which are currently used are defined
192+
#ifdef HOST_WINDOWS
192193
#define WszLoadLibrary LoadLibraryExWrapper
193194
#define WszLoadLibraryEx LoadLibraryExWrapper
194195
#define WszCreateFile CreateFileWrapper
195-
#define WszGetFileAttributes GetFileAttributesWrapper
196196
#define WszGetFileAttributesEx GetFileAttributesExWrapper
197+
#else // HOST_WINDOWS
198+
#define WszLoadLibrary LoadLibraryW
199+
#define WszLoadLibraryEx LoadLibraryExW
200+
#define WszCreateFile CreateFileW
201+
#define WszGetFileAttributesEx GetFileAttributesExW
202+
#endif // HOST_WINDOWS
197203

198204
//Can not use extended syntax
199205
#define WszGetFullPathName GetFullPathNameW

src/coreclr/jit/error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ DWORD getBreakOnBadCode()
239239
/*****************************************************************************/
240240
void debugError(const char* msg, const char* file, unsigned line)
241241
{
242-
const char* tail = strrchr(file, '\\');
242+
const char* tail = strrchr(file, DIRECTORY_SEPARATOR_CHAR_A);
243243
if (tail != nullptr)
244244
{
245245
tail = tail + 1;

src/coreclr/jit/importer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void Compiler::verRaiseVerifyExceptionIfNeeded(INDEBUG(const char* msg) DEBUGARG
8888
DEBUGARG(unsigned line))
8989
{
9090
#ifdef DEBUG
91-
const char* tail = strrchr(file, '\\');
91+
const char* tail = strrchr(file, DIRECTORY_SEPARATOR_CHAR_A);
9292
if (tail)
9393
{
9494
file = tail + 1;

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.NativeAot.Unix.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ public static partial class NativeLibrary
1111

1212
private static IntPtr LoadLibraryHelper(string libraryName, int _ /*flags*/, ref LoadLibErrorTracker errorTracker)
1313
{
14-
// do the Dos/Unix conversion
15-
libraryName = libraryName.Replace('\\', '/');
16-
1714
IntPtr ret = Interop.Sys.LoadLibrary(libraryName);
1815
if (ret == IntPtr.Zero)
1916
{

src/coreclr/pal/inc/mbusafecrt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ extern errno_t _makepath_s( char* outDest, size_t inDestBufferSize, const char*
8181
extern errno_t _wmakepath_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inDrive, const WCHAR* inDirectory, const WCHAR* inFilename, const WCHAR* inExtension );
8282

8383
extern errno_t _splitpath_s( const char* inPath, char* outDrive, size_t inDriveSize, char* outDirectory, size_t inDirectorySize, char* outFilename, size_t inFilenameSize, char* outExtension, size_t inExtensionSize );
84-
extern errno_t _wsplitpath_s( const WCHAR* inPath, WCHAR* outDrive, size_t inDriveSize, WCHAR* outDirectory, size_t inDirectorySize, WCHAR* outFilename, size_t inFilenameSize, WCHAR* outExtension, size_t inExtensionSize );
8584

8685
extern int sprintf_s( char *string, size_t sizeInBytes, const char *format, ... );
8786

0 commit comments

Comments
 (0)