diff options
author | Ionite <dev@ionite.io> | 2023-02-24 18:02:04 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-24 15:02:04 -0800 |
commit | 54dfa14c5a94b893b67a4d9e9e403ff538ce9023 (patch) | |
tree | 1b8e158aa5869aeb24749ebcd7390afdd114994e /Objects/bytesobject.c | |
parent | 89b4c1205327cc8032f4a39e3dfbdb59009a0704 (diff) | |
download | cpython-git-54dfa14c5a94b893b67a4d9e9e403ff538ce9023.tar.gz |
gh-101765: Fix SystemError / segmentation fault in iter `__reduce__` when internal access of `builtins.__dict__` exhausts the iterator (#101769)
Diffstat (limited to 'Objects/bytesobject.c')
-rw-r--r-- | Objects/bytesobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index ba2c2e978c..657443f31f 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3169,11 +3169,16 @@ PyDoc_STRVAR(length_hint_doc, static PyObject * striter_reduce(striterobject *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 != NULL) { - 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); } } |