From 4c2e1a13be27b0c44ac5c33a6c548a3d5e5faf8c Mon Sep 17 00:00:00 2001 From: Pierrick Charron Date: Tue, 26 Jul 2016 20:34:16 -0400 Subject: [PATCH] Fixed bug #72684 (AppendIterator segfault with closed generator) --- ext/spl/spl_iterators.c | 2 +- ext/spl/tests/bug72684.phpt | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ext/spl/tests/bug72684.phpt diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index a5a17d8138f..a023b11829e 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -1688,7 +1688,7 @@ static inline void spl_dual_it_rewind(spl_dual_it_object *intern TSRMLS_DC) { spl_dual_it_free(intern TSRMLS_CC); intern->current.pos = 0; - if (intern->inner.iterator->funcs->rewind) { + if (intern->inner.iterator && intern->inner.iterator->funcs->rewind) { intern->inner.iterator->funcs->rewind(intern->inner.iterator TSRMLS_CC); } } diff --git a/ext/spl/tests/bug72684.phpt b/ext/spl/tests/bug72684.phpt new file mode 100644 index 00000000000..7a99901f534 --- /dev/null +++ b/ext/spl/tests/bug72684.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #72684 (AppendIterator segfault with closed generator) +--FILE-- +append($generator); + +iterator_to_array($appendIterator); +try { + iterator_to_array($appendIterator); +} catch (\Exception $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Cannot traverse an already closed generator