From dd277409bf04177c376a97d503b283e8b3836004 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 20 Nov 2024 16:07:26 -0800 Subject: [PATCH] Fix UNC paths If the input file was a network path then the raw path returned by GetFinalPathByHandle may return a UNC path. If so, and if the original path wasn't a UNC path, we want to remove the UNC prefix unless it was necessary to fully resolve the path. --- src/native/corehost/hostmisc/pal.windows.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 06070b0b1d5da2..164e5488881c30 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -898,8 +898,13 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging) } } - // Remove the \\?\ prefix, unless it is necessary or was already there - if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && + // Remove the UNC prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there + if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && + !LongFile::ShouldNormalize(str.substr(LongFile::UNCExtendedPathPrefix.size()))) + { + str.erase(0, LongFile::UNCExtendedPathPrefix.size()); + } + else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && !LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size()))) { str.erase(0, LongFile::ExtendedPrefix.size());