bpo-36150: Fix possible assertion failures due to _ctypes.c's PyCData_reduce(). (GH-12106) (GH-12643)
https://github.com/python/cpython/commit/a110817c080ca3c2f3262350b5d7e0c0582... commit: a110817c080ca3c2f3262350b5d7e0c0582527e6 branch: 2.7 author: Zackery Spytz <zspytz@gmail.com> committer: Serhiy Storchaka <storchaka@gmail.com> date: 2019-03-31T20:14:16+03:00 summary: bpo-36150: Fix possible assertion failures due to _ctypes.c's PyCData_reduce(). (GH-12106) (GH-12643) (cherry picked from commit 5f2c50810a67982b0c80f6d3258fee3647f67005) files: M Modules/_ctypes/_ctypes.c diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 3a3aabbb6cb5..33e224386fb1 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)); }
participants (1)
-
Serhiy Storchaka