]> granicus.if.org Git - php/commitdiff
Fixed bug #73629 (SplDoublyLinkedList::setIteratorMode masks intern flags)
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 20 Sep 2017 13:36:50 +0000 (15:36 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 20 Sep 2017 13:46:04 +0000 (15:46 +0200)
We must not overwrite the SPL_DLLIST_IT_FIX flag when changing the
iterator mode.

NEWS
ext/spl/spl_dllist.c
ext/spl/tests/bug73629.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 87933990e1dc591077cba260fb8cad1cfde75d08..acc2648b382410b2099a7993ed6b08ae30fd450c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2017 PHP 7.0.25
 
-
+- SPL:
+  . Fixed bug #73629 (SplDoublyLinkedList::setIteratorMode masks intern flags).
+    (J. Jeising, cmb)
 
 28 Sep 2017 PHP 7.0.24
 
index c205de5fed8d855920511803d068b51c29d85320..db9fa838c82746f6d7e7350d067223a4642a5f6e 100644 (file)
@@ -733,7 +733,7 @@ SPL_METHOD(SplDoublyLinkedList, setIteratorMode)
                return;
        }
 
-       intern->flags = value & SPL_DLLIST_IT_MASK;
+       intern->flags = value & SPL_DLLIST_IT_MASK | intern->flags & SPL_DLLIST_IT_FIX;
 
        RETURN_LONG(intern->flags);
 }
diff --git a/ext/spl/tests/bug73629.phpt b/ext/spl/tests/bug73629.phpt
new file mode 100644 (file)
index 0000000..5b6587c
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--\r
+Bug #73629 (SplDoublyLinkedList::setIteratorMode masks intern flags)\r
+--FILE--\r
+<?php\r
+$q = new SplQueue();\r
+try {\r
+    $q->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);\r
+} catch (Exception $e) {\r
+    echo 'unexpected exception: ' . $e->getMessage() . "\n";\r
+}\r
+try {\r
+    $q->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);\r
+} catch (Exception $e) {\r
+    echo 'expected exception: ' . $e->getMessage() . "\n";\r
+}\r
+?>\r
+===DONE===\r
+--EXPECTF--\r
+expected exception: Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen\r
+===DONE===\r