[3.12] gh-115136: Fix possible NULL deref in getpath_joinpath() (GH-115137) (GH-115157)

(cherry picked from commit 9e90313320)

Signed-off-by: Artem Chernyshev <artem.chernyshev@red-soft.ru>
Co-authored-by: Artem Chernyshev <62871052+dTenebrae@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-02-08 10:18:38 +01:00 committed by GitHub
parent 2016fbd682
commit dc01c84ed0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -259,6 +259,10 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
}
/* Convert all parts to wchar and accumulate max final length */
wchar_t **parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
if (parts == NULL) {
PyErr_NoMemory();
return NULL;
}
memset(parts, 0, n * sizeof(wchar_t *));
Py_ssize_t cchFinal = 0;
Py_ssize_t first = 0;