diff options
| author | Benjamin Peterson <benjamin@python.org> | 2011-03-26 17:56:28 -0500 |
|---|---|---|
| committer | Benjamin Peterson <benjamin@python.org> | 2011-03-26 17:56:28 -0500 |
| commit | 8d6c62dd892de77295e9db7b1c56fec041726afb (patch) | |
| tree | 95c6866844be8485c210b2f456747e759e551d28 /Modules | |
| parent | b8a5769a6d35931f4dc5395686f590b5dcb58cdd (diff) | |
| download | cpython-git-8d6c62dd892de77295e9db7b1c56fec041726afb.tar.gz | |
check possible recursive _as_parameter_ to prevent segfault (closes #1838)
Diffstat (limited to 'Modules')
| -rw-r--r-- | Modules/_ctypes/_ctypes.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 04b07cc4e2..6a2b7ce7bd 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; } |
