aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2021-02-24 12:49:59 +0100
committerRon Yorston <rmy@pobox.com>2021-03-01 09:30:29 +0000
commit367f583cffcabdeebc3c27a42eba1926b5ea9819 (patch)
tree8cae79bb2d7cb5e194e4e5229f1e29e4d89c7917
parent35e32c2a7176c6add799440b642cef3fa6a70045 (diff)
downloadbusybox-w32-367f583cffcabdeebc3c27a42eba1926b5ea9819.tar.gz
busybox-w32-367f583cffcabdeebc3c27a42eba1926b5ea9819.tar.bz2
busybox-w32-367f583cffcabdeebc3c27a42eba1926b5ea9819.zip
win32: let `resolve_symlinks()` _really_ resolve symbolic links
When one tries to call `CreateFile()` with a reparse point, it will trigger an `ERROR_INVALID_NAME` unless `FILE_FLAG_OPEN_REPARSE_POINT` is passed. However, _when_ that flag is passed, it does not open a handle to the symlink _target_, but to the symlink itself. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
-rw-r--r--win32/mingw.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index e8152c87e..50ab92f0d 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1134,9 +1134,16 @@ static char *resolve_symlinks(char *path)
1134 char *ptr = NULL; 1134 char *ptr = NULL;
1135 DECLARE_PROC_ADDR(DWORD, GetFinalPathNameByHandleA, HANDLE, 1135 DECLARE_PROC_ADDR(DWORD, GetFinalPathNameByHandleA, HANDLE,
1136 LPSTR, DWORD, DWORD); 1136 LPSTR, DWORD, DWORD);
1137 char *resolve = NULL;
1138
1139 if (GetFileAttributesA(path) & FILE_ATTRIBUTE_REPARSE_POINT) {
1140 resolve = xmalloc_follow_symlinks(path);
1141 if (!resolve)
1142 return NULL;
1143 }
1137 1144
1138 /* need a file handle to resolve symlinks */ 1145 /* need a file handle to resolve symlinks */
1139 h = CreateFileA(path, 0, 0, NULL, OPEN_EXISTING, 1146 h = CreateFileA(resolve ?: path, 0, 0, NULL, OPEN_EXISTING,
1140 FILE_FLAG_BACKUP_SEMANTICS, NULL); 1147 FILE_FLAG_BACKUP_SEMANTICS, NULL);
1141 if (h != INVALID_HANDLE_VALUE) { 1148 if (h != INVALID_HANDLE_VALUE) {
1142 if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) { 1149 if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) {
@@ -1155,6 +1162,7 @@ static char *resolve_symlinks(char *path)
1155 errno = err_win_to_posix(); 1162 errno = err_win_to_posix();
1156 end: 1163 end:
1157 CloseHandle(h); 1164 CloseHandle(h);
1165 free(resolve);
1158 return ptr; 1166 return ptr;
1159} 1167}
1160 1168