diff options
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 484d374..f46d5e4 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3405,17 +3405,23 @@ listiter_reduce_general(void *_it, int forward) _Py_IDENTIFIER(reversed); PyObject *list; + /* _PyEval_GetBuiltinId can invoke arbitrary code, + * call must be before access of iterator pointers. + * see issue #101765 */ + /* the objects are not the same, index is of different types! */ if (forward) { + PyObject *iter = _PyEval_GetBuiltinId(&PyId_iter); listiterobject *it = (listiterobject *)_it; - if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), - it->it_seq, it->it_index); + if (it->it_seq) { + return Py_BuildValue("N(O)n", iter, it->it_seq, it->it_index); + } } else { + PyObject *reversed = _PyEval_GetBuiltinId(&PyId_reversed); listreviterobject *it = (listreviterobject *)_it; - if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_reversed), - it->it_seq, it->it_index); + if (it->it_seq) { + return Py_BuildValue("N(O)n", reversed, it->it_seq, it->it_index); + } } /* empty iterator, create an empty list */ list = PyList_New(0); |