diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2011-09-02 18:39:40 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2011-09-02 18:39:40 (GMT) |
commit | 02dd539dbb2ed51165f4c8138ab16f3498877971 (patch) | |
tree | e7819436d5b5d435e760526255844ea2d93483bd /Modules | |
parent | 172f374a63bfc61f71ee925463927a81350b66da (diff) | |
download | cpython-02dd539dbb2ed51165f4c8138ab16f3498877971.zip cpython-02dd539dbb2ed51165f4c8138ab16f3498877971.tar.gz cpython-02dd539dbb2ed51165f4c8138ab16f3498877971.tar.bz2 |
Issue #12764: Fix a crash in ctypes when the name of a Structure field is not
a string.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/stgdict.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 105e0df..14dc16f 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -482,8 +482,21 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct char *fieldfmt = dict->format ? dict->format : "B"; char *fieldname = _PyUnicode_AsString(name); char *ptr; - Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt); - char *buf = alloca(len + 2 + 1); + Py_ssize_t len; + char *buf; + + if (fieldname == NULL) + { + PyErr_Format(PyExc_TypeError, + "structure field name must be string not %s", + name->ob_type->tp_name); + + Py_DECREF(pair); + return -1; + } + + len = strlen(fieldname) + strlen(fieldfmt); + buf = alloca(len + 2 + 1); sprintf(buf, "%s:%s:", fieldfmt, fieldname); |