summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-03-31 17:14:16 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2019-03-31 17:14:16 (GMT)
commita110817c080ca3c2f3262350b5d7e0c0582527e6 (patch)
tree45729cdc92a0e8ee64aa99590c273b1449fea809 /Modules
parentdffe90ee0eaf77785ad3d4ad7fb3249430ed1cb9 (diff)
downloadcpython-a110817c080ca3c2f3262350b5d7e0c0582527e6.zip
cpython-a110817c080ca3c2f3262350b5d7e0c0582527e6.tar.gz
cpython-a110817c080ca3c2f3262350b5d7e0c0582527e6.tar.bz2
bpo-36150: Fix possible assertion failures due to _ctypes.c's PyCData_reduce(). (GH-12106) (GH-12643)
(cherry picked from commit 5f2c50810a67982b0c80f6d3258fee3647f67005)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 3a3aabb..33e2243 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2795,16 +2795,18 @@ static PyObject *
PyCData_reduce(PyObject *_self, PyObject *args)
{
CDataObject *self = (CDataObject *)_self;
+ PyObject *dict;
if (PyObject_stgdict(_self)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
PyErr_SetString(PyExc_ValueError,
"ctypes objects containing pointers cannot be pickled");
return NULL;
}
- return Py_BuildValue("O(O(NN))",
- _unpickle,
- Py_TYPE(_self),
- PyObject_GetAttrString(_self, "__dict__"),
+ dict = PyObject_GetAttrString(_self, "__dict__");
+ if (dict == NULL) {
+ return NULL;
+ }
+ return Py_BuildValue("O(O(NN))", _unpickle, Py_TYPE(_self), dict,
PyString_FromStringAndSize(self->b_ptr, self->b_size));
}