summaryrefslogtreecommitdiff
path: root/Modules/_ctypes/stgdict.c
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2011-10-03 21:44:22 -0500
committerMeador Inge <meadori@gmail.com>2011-10-03 21:44:22 -0500
commit975b305f4bc391cca074d1f92b70d01456abbfda (patch)
tree72da67ebec9eba049d281f7ea83c34dd758cb909 /Modules/_ctypes/stgdict.c
parent8bc2c96fcebc69073cfbe0f3ac20153ff1ccc6a7 (diff)
downloadcpython-975b305f4bc391cca074d1f92b70d01456abbfda.tar.gz
Issue #12881: ctypes: Fix segfault with large structure field names.
Diffstat (limited to 'Modules/_ctypes/stgdict.c')
-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 14dc16fc02..262d0b4897 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);