]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-139146: Check `calloc()` results in `_testembed.c::test_pre_initialization_...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 29 Sep 2025 11:03:01 +0000 (13:03 +0200)
committerGitHub <noreply@github.com>
Mon, 29 Sep 2025 11:03:01 +0000 (11:03 +0000)
gh-139146: Check `calloc()` results in `_testembed.c::test_pre_initialization_sys_options` (GH-139147)
(cherry picked from commit 9c6a1f847b648747414600f2cde18f3837505537)

Reported by: Dmitrii Chuprov <cheese@altlinux.org>

Signed-off-by: Denis Sergeev <zeff@altlinux.org>
Co-authored-by: Denis Sergeev <zeff@altlinux.org>
Programs/_testembed.c

index cc577f555715facb331962d6475cd42bec275dd9..0ff2e85a4be21c097d8037257df0ccde1c0739f8 100644 (file)
@@ -359,8 +359,18 @@ static int test_pre_initialization_sys_options(void)
     size_t xoption_len = wcslen(static_xoption);
     wchar_t *dynamic_once_warnoption = \
              (wchar_t *) calloc(warnoption_len+1, sizeof(wchar_t));
+    if (dynamic_once_warnoption == NULL) {
+        error("out of memory allocating warnoption");
+        return 1;
+    }
     wchar_t *dynamic_xoption = \
              (wchar_t *) calloc(xoption_len+1, sizeof(wchar_t));
+    if (dynamic_xoption == NULL) {
+        free(dynamic_once_warnoption);
+        error("out of memory allocating xoption");
+        return 1;
+    }
+
     wcsncpy(dynamic_once_warnoption, static_warnoption, warnoption_len+1);
     wcsncpy(dynamic_xoption, static_xoption, xoption_len+1);