diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-25 08:49:08 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-25 08:49:08 (GMT) |
commit | a6bddb8e4397df30926eb1ade6420a2277174227 (patch) | |
tree | 208f61f1f1eac173aa9947944ac2243071ec05a8 /Modules | |
parent | e2a30cd35b95dad55aea10347655f246348d1951 (diff) | |
download | cpython-a6bddb8e4397df30926eb1ade6420a2277174227.zip cpython-a6bddb8e4397df30926eb1ade6420a2277174227.tar.gz cpython-a6bddb8e4397df30926eb1ade6420a2277174227.tar.bz2 |
[3.6] bpo-31311: Fix a SystemError and a crash in ctypes._CData.__setstate__(), in case of a bad __dict__. (GH-3254) (#3743)
(cherry picked from commit 57c2561c8c5663aef55b00e3f29cba575ff36ccd)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 1ced630..27f6dd4 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -2663,6 +2663,16 @@ PyCData_setstate(PyObject *myself, PyObject *args) len = self->b_size; memmove(self->b_ptr, data, len); mydict = PyObject_GetAttrString(myself, "__dict__"); + if (mydict == NULL) { + return NULL; + } + if (!PyDict_Check(mydict)) { + PyErr_Format(PyExc_TypeError, + "%.200s.__dict__ must be a dictionary, not %.200s", + Py_TYPE(myself)->tp_name, Py_TYPE(mydict)->tp_name); + Py_DECREF(mydict); + return NULL; + } res = PyDict_Update(mydict, dict); Py_DECREF(mydict); if (res == -1) |