summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-03-26 13:35:30 (GMT)
committerGitHub <noreply@github.com>2019-03-26 13:35:30 (GMT)
commit414b1cde93764cdabb0798b02af4dd7df954424d (patch)
tree9ac9b6d3a13833383a14e3fda1d99d4307e3c35e
parent871309c775fd4d72048bfaa31affd54f9934f7dd (diff)
downloadcpython-414b1cde93764cdabb0798b02af4dd7df954424d.zip
cpython-414b1cde93764cdabb0798b02af4dd7df954424d.tar.gz
cpython-414b1cde93764cdabb0798b02af4dd7df954424d.tar.bz2
bpo-36436: Fix _testcapi.pymem_buffer_overflow() (GH-12560)
Handle memory allocation failure.
-rw-r--r--Misc/NEWS.d/next/Tests/2019-03-26-13-49-21.bpo-36436.yAtN0V.rst1
-rw-r--r--Modules/_testcapimodule.c4
2 files changed, 5 insertions, 0 deletions
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 0000000..efc9296
--- /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 c82ba0c..c515efe 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);