diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2003-06-27 16:46:45 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2003-06-27 16:46:45 (GMT) |
commit | 090a3495b3ff38750192550fd2f80b4c3552cd95 (patch) | |
tree | 6f4a0381cff1bc81fe8be91ab495b7bf934b696d /Objects | |
parent | 6ab8b40337cc79a011c4335337a1482f8df278e1 (diff) | |
download | cpython-090a3495b3ff38750192550fd2f80b4c3552cd95.zip cpython-090a3495b3ff38750192550fd2f80b4c3552cd95.tar.gz cpython-090a3495b3ff38750192550fd2f80b4c3552cd95.tar.bz2 |
Check return type of __nonzero__() method.
The language reference says you must return an int or a bool. This
fix limits the scope of SF bug 759227 (infinite recursion) to
subclasses of int.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index df9e617..7c4e744 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4196,7 +4196,19 @@ slot_nb_nonzero(PyObject *self) PyObject *temp = PyObject_Call(func, args, NULL); Py_DECREF(args); if (temp != NULL) { - result = PyObject_IsTrue(temp); + if (PyInt_Check(temp)) { + /* XXX need to guard against recursion here */ + result = PyObject_IsTrue(temp); + } + else if (PyBool_Check(temp)) + result = PyObject_IsTrue(temp); + else { + PyErr_Format(PyExc_TypeError, + "__nonzero__ should return " + "bool or int, returned %s", + temp->ob_type->tp_name); + result = NULL; + } Py_DECREF(temp); } } |