mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
e982d8b64f
commit
03a8a56fac
2 changed files with 274 additions and 166 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue