diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-09 09:07:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-09 09:07:51 (GMT) |
commit | 6e3809c7ce9fbee11c3a3f89dd7e89829b7581ac (patch) | |
tree | ad8adb7fb050731170e08732bf263331cec1fe84 /Modules | |
parent | cc1bdf91d53b1a4751be84ef607e24e69a327a9b (diff) | |
download | cpython-6e3809c7ce9fbee11c3a3f89dd7e89829b7581ac.zip cpython-6e3809c7ce9fbee11c3a3f89dd7e89829b7581ac.tar.gz cpython-6e3809c7ce9fbee11c3a3f89dd7e89829b7581ac.tar.bz2 |
bpo-34410: Fix a crash in the tee iterator when re-enter it. (GH-15625)
RuntimeError is now raised in this case.
(cherry picked from commit 526a01467b3277f9fcf7f91e66c23321caa1245d)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/itertoolsmodule.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 22c04f2..eba59ba 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -443,6 +443,7 @@ typedef struct { PyObject_HEAD PyObject *it; int numread; /* 0 <= numread <= LINKCELLS */ + int running; PyObject *nextlink; PyObject *(values[LINKCELLS]); } teedataobject; @@ -465,6 +466,7 @@ teedataobject_newinternal(PyObject *it) if (tdo == NULL) return NULL; + tdo->running = 0; tdo->numread = 0; tdo->nextlink = NULL; Py_INCREF(it); @@ -493,7 +495,14 @@ teedataobject_getitem(teedataobject *tdo, int i) else { /* this is the lead iterator, so fetch more data */ assert(i == tdo->numread); + if (tdo->running) { + PyErr_SetString(PyExc_RuntimeError, + "cannot re-enter the tee iterator"); + return NULL; + } + tdo->running = 1; value = PyIter_Next(tdo->it); + tdo->running = 0; if (value == NULL) return NULL; tdo->numread++; |