aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-11-25 15:56:37 +0000
committerRon Yorston <rmy@pobox.com>2021-11-25 16:03:39 +0000
commitc29dc205d2dc590f6d66df5a4f26efa7ada9632d (patch)
tree64341dff1c56c32cf939e72aa1dce7c18c8d1a89
parent2e8de47ad30b86f376cf2295747634c8140cfca3 (diff)
downloadbusybox-w32-c29dc205d2dc590f6d66df5a4f26efa7ada9632d.tar.gz
busybox-w32-c29dc205d2dc590f6d66df5a4f26efa7ada9632d.tar.bz2
busybox-w32-c29dc205d2dc590f6d66df5a4f26efa7ada9632d.zip
win32: fix implementation of readlink(2)
Commit 35e32c2a71 (readlink(): do `NUL`-terminate the result) changed how our implementation of readlink(2) handles the case where the link is too long for the buffer. This broke xmalloc_readlink() which expects readlink(2) to behave as documented. As a results symbolic links with 80 or more characters didn't work properly. Revert the commit. (GitHub issue #237)
-rw-r--r--win32/mingw.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index cd121c949..06da37040 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1381,10 +1381,9 @@ ssize_t readlink(const char *pathname, char *buf, size_t bufsiz)
1381 name[len] = 0; 1381 name[len] = 0;
1382 name = normalize_ntpath(name); 1382 name = normalize_ntpath(name);
1383 len = wcslen(name); 1383 len = wcslen(name);
1384 if (len >= bufsiz) 1384 if (len > bufsiz)
1385 len = bufsiz - 1; 1385 len = bufsiz;
1386 if (WideCharToMultiByte(CP_ACP, 0, name, len, buf, bufsiz, 0, 0)) { 1386 if (WideCharToMultiByte(CP_ACP, 0, name, len, buf, bufsiz, 0, 0)) {
1387 buf[len] = '\0';
1388 return len; 1387 return len;
1389 } 1388 }
1390 } 1389 }