summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-10-04 00:22:39 (GMT)
committerGitHub <noreply@github.com>2019-10-04 00:22:39 (GMT)
commit03a8a56faca0c1851051269e3517d70cbce830b7 (patch)
tree0ff81cb5696b6d951465a65a70a3a2954002ea53 /Python
parente982d8b64f5d358c578bfca5cdfe4524dbc74000 (diff)
downloadcpython-03a8a56faca0c1851051269e3517d70cbce830b7.zip
cpython-03a8a56faca0c1851051269e3517d70cbce830b7.tar.gz
cpython-03a8a56faca0c1851051269e3517d70cbce830b7.tar.bz2
bpo-38353: Add subfunctions to getpath.c (GH-16572)
Following symbolic links is now limited to 40 attempts, just to prevent loops. Add subfunctions: * Add resolve_symlinks() * Add calculate_argv0_path_framework() * Add calculate_which() * Add calculate_program_macos() Fix also _Py_wreadlink(): readlink() result type is Py_ssize_t, not int.
Diffstat (limited to 'Python')
-rw-r--r--Python/fileutils.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Python/fileutils.c b/Python/fileutils.c
index 0c05424..6345553 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -1668,8 +1668,9 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t buflen)
{
char *cpath;
char cbuf[MAXPATHLEN];
+ size_t cbuf_len = Py_ARRAY_LENGTH(cbuf);
wchar_t *wbuf;
- int res;
+ Py_ssize_t res;
size_t r1;
cpath = _Py_EncodeLocaleRaw(path, NULL);
@@ -1677,11 +1678,12 @@ _Py_wreadlink(const wchar_t *path, wchar_t *buf, size_t buflen)
errno = EINVAL;
return -1;
}
- res = (int)readlink(cpath, cbuf, Py_ARRAY_LENGTH(cbuf));
+ res = readlink(cpath, cbuf, cbuf_len);
PyMem_RawFree(cpath);
- if (res == -1)
+ if (res == -1) {
return -1;
- if (res == Py_ARRAY_LENGTH(cbuf)) {
+ }
+ if ((size_t)res == cbuf_len) {
errno = EINVAL;
return -1;
}