diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-07-24 09:45:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-24 09:45:13 (GMT) |
commit | 659030c7d56a329c1aa559678f2df15e306215e4 (patch) | |
tree | 2472aacf20968fc67df0fea1efb6d6c9d67b144e /Objects | |
parent | d15949a845a6db66675bca7105ad508ba9e79639 (diff) | |
download | cpython-659030c7d56a329c1aa559678f2df15e306215e4.zip cpython-659030c7d56a329c1aa559678f2df15e306215e4.tar.gz cpython-659030c7d56a329c1aa559678f2df15e306215e4.tar.bz2 |
bpo-44720: Don't crash when calling weakref.proxy(not_an_iterator).__next__ (GH-27316) (GH-27324)
(cherry picked from commit 5370f0a82aaa4ba617070d5c71d2b18236096ac0)
Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/weakrefobject.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index c36d239..bb56c7d 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -657,6 +657,12 @@ proxy_iternext(PyWeakReference *proxy) return NULL; PyObject *obj = PyWeakref_GET_OBJECT(proxy); + if (!PyIter_Check(obj)) { + PyErr_Format(PyExc_TypeError, + "Weakref proxy referenced a non-iterator '%.200s' object", + Py_TYPE(obj)->tp_name); + return NULL; + } Py_INCREF(obj); PyObject* res = PyIter_Next(obj); Py_DECREF(obj); |