diff options
author | Gabriel DeBacker <gabrield@microsoft.com> | 2018-09-30 16:40:22 -0700 |
---|---|---|
committer | Gabriel DeBacker <gabrield@microsoft.com> | 2018-09-30 16:40:22 -0700 |
commit | 8ab11dd53da0bba5152f1d755d92b9c436c71ff0 (patch) | |
tree | 2b6ec3ff3f544a29c44dcd7d383e54dee0353058 /src/win32 | |
parent | 1621a37dd124c6d060b2197eed01155538b0a118 (diff) | |
download | libgit2-8ab11dd53da0bba5152f1d755d92b9c436c71ff0.tar.gz |
Fix issue with path canonicalization for Win32 paths
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/w32_util.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/win32/w32_util.c b/src/win32/w32_util.c index b7b1ffa10..5bacd6ebb 100644 --- a/src/win32/w32_util.c +++ b/src/win32/w32_util.c @@ -132,6 +132,8 @@ size_t git_win32__canonicalize_path(wchar_t *str, size_t len) static const wchar_t dosdevices_prefix[] = L"\\\?\?\\"; static const wchar_t nt_prefix[] = L"\\\\?\\"; static const wchar_t unc_prefix[] = L"UNC\\"; + static const wchar_t unc_canonicalized_prefix[] = L"\\\\"; + size_t to_advance = 0; /* "\??\" -- DOS Devices prefix */ @@ -150,8 +152,18 @@ size_t git_win32__canonicalize_path(wchar_t *str, size_t len) /* "\??\UNC\", "\\?\UNC\" -- UNC prefix */ if (to_advance && len >= CONST_STRLEN(unc_prefix) && !wcsncmp(str + to_advance, unc_prefix, CONST_STRLEN(unc_prefix))) { - to_advance += CONST_STRLEN(unc_prefix); - len -= CONST_STRLEN(unc_prefix); + /** + * The proper Win32 path for a UNC share has "\\" at beginning of it + * and looks like "\\server\share\<folderStructure>". + * So, remove th UNC prefix, but leave room for a "\\" + */ + to_advance += (CONST_STRLEN(unc_prefix) - CONST_STRLEN(unc_canonicalized_prefix)); + len -= (CONST_STRLEN(unc_prefix) - CONST_STRLEN(unc_canonicalized_prefix)); + + /** + * Place a "\\" in the string so the result is "\\server\\share\<folderStructure>" + */ + memmove(str + to_advance, unc_canonicalized_prefix, CONST_STRLEN(unc_canonicalized_prefix) * sizeof(wchar_t)); } if (to_advance) { |