From: Zackery Spytz Date: Sun, 31 Mar 2019 17:14:16 +0000 (-0600) Subject: bpo-36150: Fix possible assertion failures due to _ctypes.c's PyCData_reduce(). ... X-Git-Tag: v2.7.17rc1~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a110817c080ca3c2f3262350b5d7e0c0582527e6;p=thirdparty%2FPython%2Fcpython.git bpo-36150: Fix possible assertion failures due to _ctypes.c's PyCData_reduce(). (GH-12106) (GH-12643) (cherry picked from commit 5f2c50810a67982b0c80f6d3258fee3647f67005) --- 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)); }