gh-102281: Fix potential nullptr dereference + use of uninitialized memory (gh-102282)

This commit is contained in:
Max Bachmann 2023-03-15 13:58:43 +01:00 committed by GitHub
parent 2b5781d659
commit afa6092ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1 @@
Fix potential nullptr dereference and use of uninitialized memory in fileutils. Patch by Max Bachmann.

View File

@ -446,7 +446,10 @@ getpath_realpath(PyObject *Py_UNUSED(self) , PyObject *args)
if (s) { if (s) {
*s = L'\0'; *s = L'\0';
} }
path2 = _Py_normpath(_Py_join_relfile(path, resolved), -1); path2 = _Py_join_relfile(path, resolved);
if (path2) {
path2 = _Py_normpath(path2, -1);
}
PyMem_RawFree((void *)path); PyMem_RawFree((void *)path);
path = path2; path = path2;
} }

View File

@ -2233,7 +2233,10 @@ _Py_join_relfile(const wchar_t *dirname, const wchar_t *relfile)
} }
assert(wcslen(dirname) < MAXPATHLEN); assert(wcslen(dirname) < MAXPATHLEN);
assert(wcslen(relfile) < MAXPATHLEN - wcslen(dirname)); assert(wcslen(relfile) < MAXPATHLEN - wcslen(dirname));
join_relfile(filename, bufsize, dirname, relfile); if (join_relfile(filename, bufsize, dirname, relfile) < 0) {
PyMem_RawFree(filename);
return NULL;
}
return filename; return filename;
} }
@ -2271,6 +2274,7 @@ _Py_find_basename(const wchar_t *filename)
wchar_t * wchar_t *
_Py_normpath(wchar_t *path, Py_ssize_t size) _Py_normpath(wchar_t *path, Py_ssize_t size)
{ {
assert(path != NULL);
if (!path[0] || size == 0) { if (!path[0] || size == 0) {
return path; return path;
} }