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/unicodeobject.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/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b7ec1f2..5a1865f 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -16070,14 +16070,19 @@ static PyObject * unicodeiter_reduce(unicodeiterobject *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 { PyObject *u = (PyObject *)_PyUnicode_New(0); if (u == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), u); + return Py_BuildValue("N(N)", iter, u); } } |