summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2007-12-18 19:00:59 (GMT)
committerThomas Heller <theller@ctypes.org>2007-12-18 19:00:59 (GMT)
commit8e9e4d8f95d07b5542d67da0bad9cdac2e88662a (patch)
tree8e259ae20311c869ba473c6598d9dd2131e53288 /Modules
parent52550e593d7c36121aaef766da0bf9ba79927276 (diff)
downloadcpython-8e9e4d8f95d07b5542d67da0bad9cdac2e88662a.zip
cpython-8e9e4d8f95d07b5542d67da0bad9cdac2e88662a.tar.gz
cpython-8e9e4d8f95d07b5542d67da0bad9cdac2e88662a.tar.bz2
Issue #1642: Fix segfault in ctypes when trying to delete attributes.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c16
-rw-r--r--Modules/_ctypes/cfield.c5
2 files changed, 21 insertions, 0 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 4dd35c2..fa0552c 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -791,6 +791,12 @@ CharArray_set_value(CDataObject *self, PyObject *value)
char *ptr;
int 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,
@@ -846,6 +852,11 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
{
int 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,
@@ -3969,6 +3980,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 8cb1f19..0fd82bc 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);
}