From ffbe839eadbaf6e5eb27da77861ebc88cd2f974a Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Tue, 7 Dec 2021 14:16:02 +0100 Subject: [PATCH] +fix: UNC path prefix handling issues --- src/PathLib.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/PathLib.c b/src/PathLib.c index 76adaa196..d5f2773d0 100644 --- a/src/PathLib.c +++ b/src/PathLib.c @@ -330,14 +330,16 @@ static void PrependLongPathPrefix(HPATHL hpth_in_out, bool bForce) static LPCWSTR _Path_SkipLPPrefix(const HSTRINGW hpth_str) { LPCWSTR start = StrgGet(hpth_str); - if (wcsstr(start, PATHLONG_PREFIX) == start) { + if (wcsstr(start, PATHUNC_PREFIX1) == start) { + start += wcslen(PATHUNC_PREFIX1) - 1; + } + else if (wcsstr(start, PATHLONG_PREFIX) == start) { start += wcslen(PATHLONG_PREFIX); } return start; } // ---------------------------------------------------------------------------- - static void _UnExpandEnvStrgs(HSTRINGW hstr_in_out) { if (!hstr_in_out) { @@ -404,6 +406,12 @@ static bool _PathCanonicalize(HSTRINGW hstr_in_out) size_t i, j, k; i = j = k = (start - path); + // Skip UNC Path + while ((path[i] == L'\\') && path[i + 1] == L'\\') { + i++; + } + j = k = i; + // Parse the entire string do { // Backslash separator found? @@ -1795,7 +1803,7 @@ size_t PTHAPI Path_NormalizeEx(HPATHL hpth_in_out, const HPATHL hpth_wrkdir, boo if ((wcslen(buf) < MAX_PATH_EXPLICIT) || HasOptInToRemoveMaxPathLimit()) { if ((wcsstr(ptr, PATHUNC_PREFIX1) == ptr) || (wcsstr(ptr, PATHUNC_PREFIX2) == ptr)) { - ptr += (wcslen(PATHUNC_PREFIX1) - 1); + ptr += (wcslen(PATHUNC_PREFIX1) - 2); *ptr = L'\\'; } else if (wcsstr(ptr, PATHLONG_PREFIX) == ptr) {