aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-03-08 17:27:27 +0000
committerRon Yorston <rmy@pobox.com>2019-03-08 17:27:27 +0000
commit9da32114e4779619b3cbbb4e3d795a5247e964d9 (patch)
tree242a5bad369b5f12e78d02464f8fda1d3ed0bbf7
parent3eaaac2f84e580246724725da380ac47e0ebc07e (diff)
downloadbusybox-w32-9da32114e4779619b3cbbb4e3d795a5247e964d9.tar.gz
busybox-w32-9da32114e4779619b3cbbb4e3d795a5247e964d9.tar.bz2
busybox-w32-9da32114e4779619b3cbbb4e3d795a5247e964d9.zip
win32: extend normalisation of paths in realpath(3)
The code to normalise paths in resolve_symlinks(), which is used by realpath(3), was incomplete and unable to handle UNC paths. Make an ASCII version of normalize_ntpath() to extend the cases covered. This fixes a regression introduced by commit 585d17d26 (win32: canonicalize path in chdir(2)): it wasn't possible to change to a directory with a UNC path.
-rw-r--r--win32/mingw.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index b1a8b9711..44356d6b0 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1001,6 +1001,25 @@ int link(const char *oldpath, const char *newpath)
1001 return 0; 1001 return 0;
1002} 1002}
1003 1003
1004static char *normalize_ntpathA(char *buf)
1005{
1006 /* fix absolute path prefixes */
1007 if (buf[0] == '\\') {
1008 /* strip NT namespace prefixes */
1009 if (!strncmp(buf, "\\??\\", 4) ||
1010 !strncmp(buf, "\\\\?\\", 4))
1011 buf += 4;
1012 else if (!strncasecmp(buf, "\\DosDevices\\", 12))
1013 buf += 12;
1014 /* replace remaining '...UNC\' with '\\' */
1015 if (!strncasecmp(buf, "UNC\\", 4)) {
1016 buf += 2;
1017 *buf = '\\';
1018 }
1019 }
1020 return buf;
1021}
1022
1004static char *resolve_symlinks(char *path) 1023static char *resolve_symlinks(char *path)
1005{ 1024{
1006 HANDLE h; 1025 HANDLE h;
@@ -1022,8 +1041,7 @@ static char *resolve_symlinks(char *path)
1022 status = GetFinalPathNameByHandleA(h, path, MAX_PATH, 1041 status = GetFinalPathNameByHandleA(h, path, MAX_PATH,
1023 FILE_NAME_NORMALIZED|VOLUME_NAME_DOS); 1042 FILE_NAME_NORMALIZED|VOLUME_NAME_DOS);
1024 if (status != 0 && status < MAX_PATH) { 1043 if (status != 0 && status < MAX_PATH) {
1025 /* skip '\\?\' prefix */ 1044 ptr = normalize_ntpathA(path);
1026 ptr = (!strncmp(path, "\\\\?\\", 4)) ? (path + 4) : path;
1027 goto end; 1045 goto end;
1028 } 1046 }
1029 } 1047 }