summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-03-26 22:56:28 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-03-26 22:56:28 (GMT)
commit8d6c62dd892de77295e9db7b1c56fec041726afb (patch)
tree95c6866844be8485c210b2f456747e759e551d28 /Modules
parentb8a5769a6d35931f4dc5395686f590b5dcb58cdd (diff)
downloadcpython-8d6c62dd892de77295e9db7b1c56fec041726afb.zip
cpython-8d6c62dd892de77295e9db7b1c56fec041726afb.tar.gz
cpython-8d6c62dd892de77295e9db7b1c56fec041726afb.tar.bz2
check possible recursive _as_parameter_ to prevent segfault (closes #1838)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 04b07cc..6a2b7ce 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2004,10 +2004,14 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
PyCArgObject *parg;
struct fielddesc *fd;
PyObject *as_parameter;
+ int res;
/* If the value is already an instance of the requested type,
we can use it as is */
- if (1 == PyObject_IsInstance(value, type)) {
+ res = PyObject_IsInstance(value, type);
+ if (res == -1)
+ return NULL;
+ if (res) {
Py_INCREF(value);
return value;
}
@@ -2036,7 +2040,12 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
as_parameter = PyObject_GetAttrString(value, "_as_parameter_");
if (as_parameter) {
+ if (Py_EnterRecursiveCall("while processing _as_parameter_")) {
+ Py_DECREF(as_parameter);
+ return NULL;
+ }
value = PyCSimpleType_from_param(type, as_parameter);
+ Py_LeaveRecursiveCall();
Py_DECREF(as_parameter);
return value;
}