summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-09-09 08:47:14 (GMT)
committerGitHub <noreply@github.com>2019-09-09 08:47:14 (GMT)
commit526a01467b3277f9fcf7f91e66c23321caa1245d (patch)
tree57d20cb52a4cd5e78a59403e278418908e9cd5a7 /Modules
parent918b468b7d5ebf1ec5e604cb0d99605cee38d983 (diff)
downloadcpython-526a01467b3277f9fcf7f91e66c23321caa1245d.zip
cpython-526a01467b3277f9fcf7f91e66c23321caa1245d.tar.gz
cpython-526a01467b3277f9fcf7f91e66c23321caa1245d.tar.bz2
bpo-34410: Fix a crash in the tee iterator when re-enter it. (GH-15625)
RuntimeError is now raised in this case.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/itertoolsmodule.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index cf419ad..e60ad5b 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++;