From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 26 Mar 2019 15:39:03 +0000 (-0700) Subject: bpo-36436: Fix _testcapi.pymem_buffer_overflow() (GH-12560) X-Git-Tag: v3.7.4rc1~292 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=20fde53a25aefd076d8478f67d6db3908459c6f3;p=thirdparty%2FPython%2Fcpython.git bpo-36436: Fix _testcapi.pymem_buffer_overflow() (GH-12560) Handle memory allocation failure. (cherry picked from commit 414b1cde93764cdabb0798b02af4dd7df954424d) Co-authored-by: Victor Stinner --- 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 000000000000..efc9296ad622 --- /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 eb050ff112e8..1e33ca872d45 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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);