From 03a8a56faca0c1851051269e3517d70cbce830b7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 4 Oct 2019 02:22:39 +0200 Subject: 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. --- Python/fileutils.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Python/fileutils.c') diff --git a/Python/fileutils.c b/Python/fileutils.c index 0c05424143..6345553f48 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; } -- cgit v1.2.1