Skip to content

Commit 6091bce

Browse files
github-actions[bot]agockeelinor-fung
authored
[release/9.0-staging] Fix UNC paths (#111499)
* 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, and the original path doesn't need normalization, we want to use the original path. * Use MAXPATH instead * Update src/native/corehost/hostmisc/pal.windows.cpp Co-authored-by: Elinor Fung <[email protected]> * Update src/native/corehost/hostmisc/pal.windows.cpp Co-authored-by: Elinor Fung <[email protected]> --------- Co-authored-by: Andy Gocke <[email protected]> Co-authored-by: Elinor Fung <[email protected]>
1 parent 77e45d3 commit 6091bce

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/native/corehost/hostmisc/pal.windows.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,12 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging)
884884
}
885885
}
886886

887-
// Remove the \\?\ prefix, unless it is necessary or was already there
888-
if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
887+
// Remove the UNC extended prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there
888+
if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && str.length() < MAX_PATH)
889+
{
890+
str.replace(0, LongFile::UNCExtendedPathPrefix.size(), LongFile::UNCPathPrefix);
891+
}
892+
else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) &&
889893
!LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size())))
890894
{
891895
str.erase(0, LongFile::ExtendedPrefix.size());

0 commit comments

Comments
 (0)