]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36436: Fix _testcapi.pymem_buffer_overflow() (GH-12560)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 26 Mar 2019 15:39:03 +0000 (08:39 -0700)
committerGitHub <noreply@github.com>
Tue, 26 Mar 2019 15:39:03 +0000 (08:39 -0700)
Handle memory allocation failure.
(cherry picked from commit 414b1cde93764cdabb0798b02af4dd7df954424d)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
Misc/NEWS.d/next/Tests/2019-03-26-13-49-21.bpo-36436.yAtN0V.rst [new file with mode: 0644]
Modules/_testcapimodule.c

diff --git a/Misc/NEWS.d/next/Tests/2019-03-26-13-49-21.bpo-36436.yAtN0V.rst b/Misc/NEWS.d/next/Tests/2019-03-26-13-49-21.bpo-36436.yAtN0V.rst
new file mode 100644 (file)
index 0000000..efc9296
--- /dev/null
@@ -0,0 +1 @@
+Fix ``_testcapi.pymem_buffer_overflow()``: handle memory allocation failure.
index eb050ff112e80ce5848fbe73cc168dc0c75f1916..1e33ca872d456ac842025d61cb8deb0a6cdc7df4 100644 (file)
@@ -4175,6 +4175,10 @@ pymem_buffer_overflow(PyObject *self, PyObject *args)
     /* Deliberate buffer overflow to check that PyMem_Free() detects
        the overflow when debug hooks are installed. */
     buffer = PyMem_Malloc(16);
+    if (buffer == NULL) {
+        PyErr_NoMemory();
+        return NULL;
+    }
     buffer[16] = 'x';
     PyMem_Free(buffer);