summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2011-10-04 02:44:22 (GMT)
committerMeador Inge <meadori@gmail.com>2011-10-04 02:44:22 (GMT)
commit1efb33a6823b94739e59d6e2fe92e8e703a7fc7d (patch)
tree86f8d676cb9b8ca47f20e63f8533de58b8e0c28c /Modules
parent5d0de3fbaa6d3c6ba9c1c510a943df249bdd61e7 (diff)
downloadcpython-1efb33a6823b94739e59d6e2fe92e8e703a7fc7d.zip
cpython-1efb33a6823b94739e59d6e2fe92e8e703a7fc7d.tar.gz
cpython-1efb33a6823b94739e59d6e2fe92e8e703a7fc7d.tar.bz2
Issue #12881: ctypes: Fix segfault with large structure field names.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/stgdict.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c
index 14dc16f..262d0b4 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -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);