diff options
author | Ionite <dev@ionite.io> | 2023-02-24 23:02:04 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 23:02:04 (GMT) |
commit | 54dfa14c5a94b893b67a4d9e9e403ff538ce9023 (patch) | |
tree | 1b8e158aa5869aeb24749ebcd7390afdd114994e /Objects/tupleobject.c | |
parent | 89b4c1205327cc8032f4a39e3dfbdb59009a0704 (diff) | |
download | cpython-54dfa14c5a94b893b67a4d9e9e403ff538ce9023.zip cpython-54dfa14c5a94b893b67a4d9e9e403ff538ce9023.tar.gz cpython-54dfa14c5a94b893b67a4d9e9e403ff538ce9023.tar.bz2 |
gh-101765: Fix SystemError / segmentation fault in iter `__reduce__` when internal access of `builtins.__dict__` exhausts the iterator (#101769)
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r-- | Objects/tupleobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 7d6d0e1..6ee93ab 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1048,11 +1048,16 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * tupleiter_reduce(_PyTupleIterObject *it, PyObject *Py_UNUSED(ignored)) { + PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter)); + + /* _PyEval_GetBuiltin can invoke arbitrary code, + * call must be before access of iterator pointers. + * see issue #101765 */ + if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)), - it->it_seq, it->it_index); + return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter))); + return Py_BuildValue("N(())", iter); } static PyObject * |