Issue #12764: Fix a crash in ctypes when the name of a Structure field is not

a string.
This commit is contained in:
Amaury Forgeot d'Arc 2011-09-02 20:39:40 +02:00
parent 172f374a63
commit 02dd539dbb
3 changed files with 26 additions and 2 deletions

View file

@ -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);