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)
commitf21ad92351584b4c0163cdeb6d877317fdc53ea3 (patch)
tree879b1e6fde962d006b81f13442c6babf70a0ba8d /Modules
parent41347fe011c4cb8725b18f0b0bd4812089f4cae0 (diff)
downloadcpython-f21ad92351584b4c0163cdeb6d877317fdc53ea3.zip
cpython-f21ad92351584b4c0163cdeb6d877317fdc53ea3.tar.gz
cpython-f21ad92351584b4c0163cdeb6d877317fdc53ea3.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 bb406c6..d008576 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -2065,10 +2065,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;
}
@@ -2097,7 +2101,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;
}