diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-30 17:40:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-30 17:40:02 (GMT) |
commit | fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa (patch) | |
tree | 4ae6657a598c5cfe5357f3106d956ed721d83e24 /Objects/listobject.c | |
parent | 13b3acd13e35b5e619c3d1aab90aaf54abc1fb53 (diff) | |
download | cpython-fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa.zip cpython-fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa.tar.gz cpython-fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa.tar.bz2 |
Issue #26494: Fixed crash on iterating exhausting iterators.
Affected classes are generic sequence iterators, iterators of str, bytes,
bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding
views and os.scandir() iterator.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index eee7c68..d688179 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2782,8 +2782,8 @@ listiter_next(listiterobject *it) return item; } - Py_DECREF(seq); it->it_seq = NULL; + Py_DECREF(seq); return NULL; } @@ -2912,9 +2912,17 @@ static PyObject * listreviter_next(listreviterobject *it) { PyObject *item; - Py_ssize_t index = it->it_index; - PyListObject *seq = it->it_seq; + Py_ssize_t index; + PyListObject *seq; + + assert(it != NULL); + seq = it->it_seq; + if (seq == NULL) { + return NULL; + } + assert(PyList_Check(seq)); + index = it->it_index; if (index>=0 && index < PyList_GET_SIZE(seq)) { item = PyList_GET_ITEM(seq, index); it->it_index--; @@ -2922,10 +2930,8 @@ listreviter_next(listreviterobject *it) return item; } it->it_index = -1; - if (seq != NULL) { - it->it_seq = NULL; - Py_DECREF(seq); - } + it->it_seq = NULL; + Py_DECREF(seq); return NULL; } |