summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapi
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-01-31 11:11:35 (GMT)
committerGitHub <noreply@github.com>2024-01-31 11:11:35 (GMT)
commitb7688ef71eddcaf14f71b1c22ff2f164f34b2c74 (patch)
tree08f81ce254f5876bd674d680c5e20050cf6f7c49 /Modules/_testcapi
parent7a93db44257c0404dc407ff2ddc997f4bb8890ed (diff)
downloadcpython-b7688ef71eddcaf14f71b1c22ff2f164f34b2c74.zip
cpython-b7688ef71eddcaf14f71b1c22ff2f164f34b2c74.tar.gz
cpython-b7688ef71eddcaf14f71b1c22ff2f164f34b2c74.tar.bz2
gh-114685: Check flags in PyObject_GetBuffer() (GH-114707)
PyObject_GetBuffer() now raises a SystemError if called with PyBUF_READ or PyBUF_WRITE as flags. These flags should only be used with the PyMemoryView_* C API.
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r--Modules/_testcapi/buffer.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Modules/_testcapi/buffer.c b/Modules/_testcapi/buffer.c
index 9427741..7e2f6e5 100644
--- a/Modules/_testcapi/buffer.c
+++ b/Modules/_testcapi/buffer.c
@@ -54,8 +54,10 @@ static int
testbuf_getbuf(testBufObject *self, Py_buffer *view, int flags)
{
int buf = PyObject_GetBuffer(self->obj, view, flags);
- Py_SETREF(view->obj, Py_NewRef(self));
- self->references++;
+ if (buf == 0) {
+ Py_SETREF(view->obj, Py_NewRef(self));
+ self->references++;
+ }
return buf;
}