summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2011-10-04 02:48:30 (GMT)
committerMeador Inge <meadori@gmail.com>2011-10-04 02:48:30 (GMT)
commit29f43f7368115c47c97acff02816a680c3ebd73e (patch)
treec1755ccd2aed68c389121f1a94044a7e89d9a06e /Modules
parent7f3140ef800872716bebaa2e605e0304b6f7ff1b (diff)
parent1efb33a6823b94739e59d6e2fe92e8e703a7fc7d (diff)
downloadcpython-29f43f7368115c47c97acff02816a680c3ebd73e.zip
cpython-29f43f7368115c47c97acff02816a680c3ebd73e.tar.gz
cpython-29f43f7368115c47c97acff02816a680c3ebd73e.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 63f956b..e5b0e4c 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -493,13 +493,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);