Co-authored-by: Victor Stinner <vstinner@python.org>
--- /dev/null
+Fix buffer overflow in ``_Py_wrealpath()`` for paths exceeding ``MAXPATHLEN`` bytes
+by using dynamic memory allocation instead of fixed-size buffer.
+Patch by Shamil Abdulaev.
wchar_t *resolved_path, size_t resolved_path_len)
{
char *cpath;
- char cresolved_path[MAXPATHLEN];
wchar_t *wresolved_path;
char *res;
size_t r;
errno = EINVAL;
return NULL;
}
- res = realpath(cpath, cresolved_path);
+ res = realpath(cpath, NULL);
PyMem_RawFree(cpath);
if (res == NULL)
return NULL;
- wresolved_path = Py_DecodeLocale(cresolved_path, &r);
+ wresolved_path = Py_DecodeLocale(res, &r);
+ free(res);
+
if (wresolved_path == NULL) {
errno = EINVAL;
return NULL;