diff options
author | Thomas Heller <theller@ctypes.org> | 2007-12-18 19:00:34 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2007-12-18 19:00:34 (GMT) |
commit | 153038efa4fa1b2e9819703abf22bddf76a62e9f (patch) | |
tree | 0585ce11abee572dd91570a124764ae9d84a7cfb /Modules | |
parent | effde12f5fe41bab9c27269bd77237200d953afd (diff) | |
download | cpython-153038efa4fa1b2e9819703abf22bddf76a62e9f.zip cpython-153038efa4fa1b2e9819703abf22bddf76a62e9f.tar.gz cpython-153038efa4fa1b2e9819703abf22bddf76a62e9f.tar.bz2 |
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 16 | ||||
-rw-r--r-- | Modules/_ctypes/cfield.c | 5 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index d564fb9..03e2e7a 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -788,6 +788,12 @@ CharArray_set_value(CDataObject *self, PyObject *value) char *ptr; Py_ssize_t size; + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, + "can't delete attribute"); + return -1; + } + if (PyUnicode_Check(value)) { value = PyUnicode_AsEncodedString(value, conversion_mode_encoding, @@ -843,6 +849,11 @@ WCharArray_set_value(CDataObject *self, PyObject *value) { Py_ssize_t result = 0; + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, + "can't delete attribute"); + return -1; + } if (PyString_Check(value)) { value = PyUnicode_FromEncodedObject(value, conversion_mode_encoding, @@ -4139,6 +4150,11 @@ Simple_set_value(CDataObject *self, PyObject *value) PyObject *result; StgDictObject *dict = PyObject_stgdict((PyObject *)self); + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, + "can't delete attribute"); + return -1; + } assert(dict); /* Cannot be NULL for CDataObject instances */ assert(dict->setfunc); result = dict->setfunc(self->b_ptr, value, dict->size); diff --git a/Modules/_ctypes/cfield.c b/Modules/_ctypes/cfield.c index 77667f5..8857e44 100644 --- a/Modules/_ctypes/cfield.c +++ b/Modules/_ctypes/cfield.c @@ -199,6 +199,11 @@ CField_set(CFieldObject *self, PyObject *inst, PyObject *value) assert(CDataObject_Check(inst)); dst = (CDataObject *)inst; ptr = dst->b_ptr + self->offset; + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, + "can't delete attribute"); + return -1; + } return CData_set(inst, self->proto, self->setfunc, value, self->index, self->size, ptr); } |