mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-101765: Fix SystemError / segmentation fault in iter __reduce__ when internal access of builtins.__dict__ exhausts the iterator (#101769)
This commit is contained in:
parent
89b4c12053
commit
54dfa14c5a
9 changed files with 148 additions and 23 deletions
|
|
@ -877,8 +877,17 @@ ga_iter_clear(PyObject *self) {
|
|||
static PyObject *
|
||||
ga_iter_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *iter = _PyEval_GetBuiltin(&_Py_ID(iter));
|
||||
gaiterobject *gi = (gaiterobject *)self;
|
||||
return Py_BuildValue("N(O)", _PyEval_GetBuiltin(&_Py_ID(iter)), gi->obj);
|
||||
|
||||
/* _PyEval_GetBuiltin can invoke arbitrary code,
|
||||
* call must be before access of iterator pointers.
|
||||
* see issue #101765 */
|
||||
|
||||
if (gi->obj)
|
||||
return Py_BuildValue("N(O)", iter, gi->obj);
|
||||
else
|
||||
return Py_BuildValue("N(())", iter);
|
||||
}
|
||||
|
||||
static PyMethodDef ga_iter_methods[] = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue