diff options
author | Ionite <dev@ionite.io> | 2023-02-25 03:50:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-25 03:50:53 (GMT) |
commit | 9f472f81bc2636eda212c12796b8d6581783bcef (patch) | |
tree | 55e89ad5142c112bc8ff0c63af7c5a62b5f6f1df /Objects/bytesobject.c | |
parent | 3e80d21b7673edf70753e14d88907c60bc6970c3 (diff) | |
download | cpython-9f472f81bc2636eda212c12796b8d6581783bcef.zip cpython-9f472f81bc2636eda212c12796b8d6581783bcef.tar.gz cpython-9f472f81bc2636eda212c12796b8d6581783bcef.tar.bz2 |
[3.10] gh-101765: Fix SystemError / segmentation fault in iter `__reduce__` when internal access of `builtins.__dict__` exhausts the iterator (GH-101769) (#102229)
(cherry picked from commit 54dfa14c5a94b893b67a4d9e9e403ff538ce9023)
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 4bcb2eb..acbc26a 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3146,11 +3146,16 @@ static PyObject * striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) { _Py_IDENTIFIER(iter); + PyObject *iter = _PyEval_GetBuiltinId(&PyId_iter); + + /* _PyEval_GetBuiltinId 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_GetBuiltinId(&PyId_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_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", iter); } } |