aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-03-09 06:24:42 +0000
committerRon Yorston <rmy@pobox.com>2024-03-09 06:24:42 +0000
commit912d65cba97db3d27a747decb1c1635aece8bb90 (patch)
tree3654619ff5de80e74199a721ee0e12cefe802742
parentc6e443f10f4467bf2892e86defdec13c25a51cff (diff)
downloadbusybox-w32-912d65cba97db3d27a747decb1c1635aece8bb90.tar.gz
busybox-w32-912d65cba97db3d27a747decb1c1635aece8bb90.tar.bz2
busybox-w32-912d65cba97db3d27a747decb1c1635aece8bb90.zip
win32: improvements to realpath(3)
The previous commit unnecessarily duplicated the path returned from resolve_symlinks(), resulting in a memory leak. Thanks to avih for spotting this. Even if we can't canonicalise the path in resolve_symlinks() we can at least return the result of resolving the trailing symlink. Moreover, this can be done both when the necessary API is missing and when the filesystem doesn't support it. Not perfect, but better than nothing, and there's no cost. This change gets rid of a handful of realpath-related test failures on ReactOS and Windows XP. Some background: Commit 8ebe81483 returned the raw path when the required API was missing. This was reverted in commit f902184fa because it caused an infinite loop (GitHub issue #204). Commit 31467ddfc fixed the cause of the loop, which is why it's now safe to reintroduce a fallback return. (GitHub commit #389)
-rw-r--r--win32/mingw.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index eef3ab5d3..a8170bb9c 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1551,7 +1551,9 @@ static char *resolve_symlinks(char *path)
1551 FILE_FLAG_BACKUP_SEMANTICS, NULL); 1551 FILE_FLAG_BACKUP_SEMANTICS, NULL);
1552 if (h != INVALID_HANDLE_VALUE) { 1552 if (h != INVALID_HANDLE_VALUE) {
1553 if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) { 1553 if (!INIT_PROC_ADDR(kernel32.dll, GetFinalPathNameByHandleA)) {
1554 errno = ENOSYS; 1554 if (resolve)
1555 strcpy(path, resolve);
1556 ptr = path;
1555 goto end; 1557 goto end;
1556 } 1558 }
1557 1559
@@ -1562,7 +1564,9 @@ static char *resolve_symlinks(char *path)
1562 ptr = normalize_ntpathA(path); 1564 ptr = normalize_ntpathA(path);
1563 goto end; 1565 goto end;
1564 } else if (err_win_to_posix() == ENOSYS) { 1566 } else if (err_win_to_posix() == ENOSYS) {
1565 ptr = xstrdup(path); 1567 if (resolve)
1568 strcpy(path, resolve);
1569 ptr = path;
1566 goto end; 1570 goto end;
1567 } 1571 }
1568 } 1572 }