summaryrefslogtreecommitdiffstats
path: root/Modules/_ctypes
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2011-10-04 02:34:04 (GMT)
committerMeador Inge <meadori@gmail.com>2011-10-04 02:34:04 (GMT)
commitad349a190e923b32e7ef43ddafffde93df75051a (patch)
treee4b1751719ea6cc935e1f56fd9f904db17b22f55 /Modules/_ctypes
parent83cc512a01d33d5e6fcc3be2ce62a9a644dd3b50 (diff)
downloadcpython-ad349a190e923b32e7ef43ddafffde93df75051a.zip
cpython-ad349a190e923b32e7ef43ddafffde93df75051a.tar.gz
cpython-ad349a190e923b32e7ef43ddafffde93df75051a.tar.bz2
Issue #12881: ctypes: Fix segfault with large structure field names.
Diffstat (limited to 'Modules/_ctypes')
-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 4d4ecc4..773233f 100644
--- a/Modules/_ctypes/stgdict.c
+++ b/Modules/_ctypes/stgdict.c
@@ -508,13 +508,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);