mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #12881: ctypes: Fix segfault with large structure field names.
This commit is contained in:
parent
5d0de3fbaa
commit
1efb33a682
3 changed files with 21 additions and 1 deletions
|
@ -496,13 +496,19 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
|
|||
}
|
||||
|
||||
len = strlen(fieldname) + strlen(fieldfmt);
|
||||
buf = alloca(len + 2 + 1);
|
||||
|
||||
buf = PyMem_Malloc(len + 2 + 1);
|
||||
if (buf == NULL) {
|
||||
Py_DECREF(pair);
|
||||
PyErr_NoMemory();
|
||||
return -1;
|
||||
}
|
||||
sprintf(buf, "%s:%s:", fieldfmt, fieldname);
|
||||
|
||||
ptr = stgdict->format;
|
||||
stgdict->format = _ctypes_alloc_format_string(stgdict->format, buf);
|
||||
PyMem_Free(ptr);
|
||||
PyMem_Free(buf);
|
||||
|
||||
if (stgdict->format == NULL) {
|
||||
Py_DECREF(pair);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue