mirror of
https://github.com/python/cpython.git
synced 2025-12-07 13:50:06 +00:00
gh-42400: Fix buffer overflow in _Py_wrealpath() for very long paths (#141529)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
600f3feb23
commit
daafacf005
2 changed files with 7 additions and 3 deletions
|
|
@ -0,0 +1,3 @@
|
|||
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.
|
||||
|
|
@ -2118,7 +2118,6 @@ _Py_wrealpath(const wchar_t *path,
|
|||
wchar_t *resolved_path, size_t resolved_path_len)
|
||||
{
|
||||
char *cpath;
|
||||
char cresolved_path[MAXPATHLEN];
|
||||
wchar_t *wresolved_path;
|
||||
char *res;
|
||||
size_t r;
|
||||
|
|
@ -2127,12 +2126,14 @@ _Py_wrealpath(const wchar_t *path,
|
|||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue