summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-10-12 17:54:48 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-10-12 17:54:48 (GMT)
commit817905b2393b03e035d2bbfc8d92b7bbeaddb118 (patch)
tree7d6a5e458918e5407c975d05a387201b14e142ea /Modules
parent4cfb5bee89965c7b85772ee2d0c3bf689acd23b2 (diff)
downloadcpython-817905b2393b03e035d2bbfc8d92b7bbeaddb118.zip
cpython-817905b2393b03e035d2bbfc8d92b7bbeaddb118.tar.gz
cpython-817905b2393b03e035d2bbfc8d92b7bbeaddb118.tar.bz2
#13096: Fix segfault in CTypes POINTER handling of large values.
Patch by Meador Inge.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/callproc.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index dcabbdf..6cf358c 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -1672,24 +1672,30 @@ POINTER(PyObject *self, PyObject *cls)
}
if (PyUnicode_CheckExact(cls)) {
char *name = _PyUnicode_AsString(cls);
- buf = alloca(strlen(name) + 3 + 1);
+ buf = PyMem_Malloc(strlen(name) + 3 + 1);
+ if (buf == NULL)
+ return PyErr_NoMemory();
sprintf(buf, "LP_%s", name);
result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type),
"s(O){}",
buf,
&PyCPointer_Type);
+ PyMem_Free(buf);
if (result == NULL)
return result;
key = PyLong_FromVoidPtr(result);
} else if (PyType_Check(cls)) {
typ = (PyTypeObject *)cls;
- buf = alloca(strlen(typ->tp_name) + 3 + 1);
+ buf = PyMem_Malloc(strlen(typ->tp_name) + 3 + 1);
+ if (buf == NULL)
+ return PyErr_NoMemory();
sprintf(buf, "LP_%s", typ->tp_name);
result = PyObject_CallFunction((PyObject *)Py_TYPE(&PyCPointer_Type),
"s(O){sO}",
buf,
&PyCPointer_Type,
"_type_", cls);
+ PyMem_Free(buf);
if (result == NULL)
return result;
Py_INCREF(cls);