From 71ad80d5d83b42c7e60cae06378ee73b5ea0b128 Mon Sep 17 00:00:00 2001 From: Artem Chernyshev <62871052+dTenebrae@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:40:38 +0300 Subject: [PATCH] gh-115136: Fix possible NULL deref in getpath_joinpath() (GH-115137) (cherry picked from commit 9e90313320a2af2d9ff7049ed3842344ed236630) Co-authored-by: Artem Chernyshev <62871052+dTenebrae@users.noreply.github.com> Signed-off-by: Artem Chernyshev --- Modules/getpath.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/getpath.c b/Modules/getpath.c index 2a14de0c915e9b..61d654065fdca0 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -265,6 +265,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;