From 602d307ac5e8a2da38a193dca3bdfef5994dfe67 Mon Sep 17 00:00:00 2001 From: Zackery Spytz Date: Fri, 7 Dec 2018 05:17:43 -0700 Subject: bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015) (GH-11020) (cherry picked from commit 4c49da0cb7434c676d70b9ccf38aca82ac0d64a9) --- PC/getpathp.c | 12 ++++++++++-- PC/launcher.c | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'PC') diff --git a/PC/getpathp.c b/PC/getpathp.c index 4075463f22..1b553d53af 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -576,6 +576,9 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path, size_t prefixlen = wcslen(prefix); wchar_t *buf = (wchar_t*)PyMem_RawMalloc(bufsiz * sizeof(wchar_t)); + if (buf == NULL) { + goto error; + } buf[0] = '\0'; while (!feof(sp_file)) { @@ -603,17 +606,22 @@ read_pth_file(_PyPathConfig *config, wchar_t *prefix, const wchar_t *path, DWORD wn = MultiByteToWideChar(CP_UTF8, 0, line, -1, NULL, 0); wchar_t *wline = (wchar_t*)PyMem_RawMalloc((wn + 1) * sizeof(wchar_t)); + if (wline == NULL) { + goto error; + } wn = MultiByteToWideChar(CP_UTF8, 0, line, -1, wline, wn + 1); wline[wn] = '\0'; size_t usedsiz = wcslen(buf); while (usedsiz + wn + prefixlen + 4 > bufsiz) { bufsiz += MAXPATHLEN; - buf = (wchar_t*)PyMem_RawRealloc(buf, (bufsiz + 1) * sizeof(wchar_t)); - if (!buf) { + wchar_t *tmp = (wchar_t*)PyMem_RawRealloc(buf, (bufsiz + 1) * + sizeof(wchar_t)); + if (tmp == NULL) { PyMem_RawFree(wline); goto error; } + buf = tmp; } if (usedsiz) { diff --git a/PC/launcher.c b/PC/launcher.c index 0242f26391..4c620dab7c 100644 --- a/PC/launcher.c +++ b/PC/launcher.c @@ -1763,6 +1763,9 @@ process(int argc, wchar_t ** argv) } cch += (DWORD)wcslen(PYTHON_EXECUTABLE) + 1 + 1; /* include sep and null */ executable = (wchar_t *)malloc(cch * sizeof(wchar_t)); + if (executable == NULL) { + error(RC_NO_MEMORY, L"A memory allocation failed"); + } cch_actual = MultiByteToWideChar(CP_UTF8, 0, start, len, executable, cch); if (!cch_actual) { error(RC_BAD_VENV_CFG, L"Cannot decode home path in '%ls'", -- cgit v1.2.1