mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[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 54dfa14c5a
)
This commit is contained in:
parent
3e80d21b76
commit
9f472f81bc
8 changed files with 141 additions and 24 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue