From 414b1cde93764cdabb0798b02af4dd7df954424d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 26 Mar 2019 14:35:30 +0100 Subject: [PATCH] bpo-36436: Fix _testcapi.pymem_buffer_overflow() (GH-12560) Handle memory allocation failure. --- .../next/Tests/2019-03-26-13-49-21.bpo-36436.yAtN0V.rst | 1 + Modules/_testcapimodule.c | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-03-26-13-49-21.bpo-36436.yAtN0V.rst 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 index 00000000000..efc9296ad62 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-03-26-13-49-21.bpo-36436.yAtN0V.rst @@ -0,0 +1 @@ +Fix ``_testcapi.pymem_buffer_overflow()``: handle memory allocation failure. diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index c82ba0cfd0d..c515efe660b 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4184,6 +4184,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);