diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-30 17:41:15 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-03-30 17:41:15 (GMT) |
commit | ab479c49d31be03e85b824b8444b474b28e6db71 (patch) | |
tree | f171c7cb1f6e5568b7309665b0e87dae9dda67f5 /Objects | |
parent | fe4c01268cf9e94869a476495213fc362ef3a697 (diff) | |
parent | fbb1c5ee068d209e33f6e15ecb4821d5d8b107fa (diff) | |
download | cpython-ab479c49d31be03e85b824b8444b474b28e6db71.zip cpython-ab479c49d31be03e85b824b8444b474b28e6db71.tar.gz cpython-ab479c49d31be03e85b824b8444b474b28e6db71.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')
-rw-r--r-- | Objects/bytearrayobject.c | 2 | ||||
-rw-r--r-- | Objects/bytesobject.c | 2 | ||||
-rw-r--r-- | Objects/dictobject.c | 6 | ||||
-rw-r--r-- | Objects/iterobject.c | 2 | ||||
-rw-r--r-- | Objects/listobject.c | 20 | ||||
-rw-r--r-- | Objects/setobject.c | 2 | ||||
-rw-r--r-- | Objects/tupleobject.c | 2 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 2 |
8 files changed, 22 insertions, 16 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 209a641..7748859 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -3126,8 +3126,8 @@ bytearrayiter_next(bytesiterobject *it) return item; } - Py_DECREF(seq); it->it_seq = NULL; + Py_DECREF(seq); return NULL; } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 5b9006e..5bbbcde 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -3806,8 +3806,8 @@ striter_next(striterobject *it) return item; } - Py_DECREF(seq); it->it_seq = NULL; + Py_DECREF(seq); return NULL; } diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 0fa8241..31c45ef 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2988,8 +2988,8 @@ static PyObject *dictiter_iternextkey(dictiterobject *di) return key; fail: - Py_DECREF(d); di->di_dict = NULL; + Py_DECREF(d); return NULL; } @@ -3069,8 +3069,8 @@ static PyObject *dictiter_iternextvalue(dictiterobject *di) return value; fail: - Py_DECREF(d); di->di_dict = NULL; + Py_DECREF(d); return NULL; } @@ -3164,8 +3164,8 @@ static PyObject *dictiter_iternextitem(dictiterobject *di) return result; fail: - Py_DECREF(d); di->di_dict = NULL; + Py_DECREF(d); return NULL; } diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 2fb0c88..ab29ff8 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -69,8 +69,8 @@ iter_iternext(PyObject *iterator) PyErr_ExceptionMatches(PyExc_StopIteration)) { PyErr_Clear(); - Py_DECREF(seq); it->it_seq = NULL; + Py_DECREF(seq); } return NULL; } diff --git a/Objects/listobject.c b/Objects/listobject.c index bcf587c..81b40ae 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2776,8 +2776,8 @@ listiter_next(listiterobject *it) return item; } - Py_DECREF(seq); it->it_seq = NULL; + Py_DECREF(seq); return NULL; } @@ -2906,9 +2906,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--; @@ -2916,10 +2924,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; } diff --git a/Objects/setobject.c b/Objects/setobject.c index 176570e..ac71b2c 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -916,8 +916,8 @@ static PyObject *setiter_iternext(setiterobject *si) return key; fail: - Py_DECREF(so); si->si_set = NULL; + Py_DECREF(so); return NULL; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 8e1b00b..5020aff 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -961,8 +961,8 @@ tupleiter_next(tupleiterobject *it) return item; } - Py_DECREF(seq); it->it_seq = NULL; + Py_DECREF(seq); return NULL; } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index d0321ba..8dc2a38 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15401,8 +15401,8 @@ unicodeiter_next(unicodeiterobject *it) return item; } - Py_DECREF(seq); it->it_seq = NULL; + Py_DECREF(seq); return NULL; } |