File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ PHP NEWS
2424 . Fixed bug GH-18139 (Memory leak when overriding some settings
2525 via readline_info()). (ndossche)
2626
27+ - SPL:
28+ . Fixed bug GH-20856 (heap-use-after-free in SplDoublyLinkedList iterator
29+ when modifying during iteration). (ndossche)
30+
2731- Standard:
2832 . Fixed bug #74357 (lchown fails to change ownership of symlink with ZTS)
2933 (Jakub Zelenka)
Original file line number Diff line number Diff line change @@ -764,11 +764,10 @@ PHP_METHOD(SplDoublyLinkedList, offsetUnset)
764764 element = spl_ptr_llist_offset (intern -> llist , index , intern -> flags & SPL_DLLIST_IT_LIFO );
765765
766766 if (element != NULL ) {
767- /* connect the neighbors */
767+ /* disconnect the neighbours */
768768 if (element -> prev ) {
769769 element -> prev -> next = element -> next ;
770770 }
771-
772771 if (element -> next ) {
773772 element -> next -> prev = element -> prev ;
774773 }
@@ -782,6 +781,10 @@ PHP_METHOD(SplDoublyLinkedList, offsetUnset)
782781 llist -> tail = element -> prev ;
783782 }
784783
784+ /* Keep consistency if element is kept alive. */
785+ element -> prev = NULL ;
786+ element -> next = NULL ;
787+
785788 /* finally, delete the element */
786789 llist -> count -- ;
787790
Original file line number Diff line number Diff line change 1+ --TEST--
2+ GH-20856 (heap-use-after-free in SplDoublyLinkedList iterator when modifying during iteration)
3+ --CREDITS--
4+ vi3tL0u1s
5+ iluuu1994
6+ --FILE--
7+ <?php
8+ $ m = new SplStack ;
9+ $ m [] = new stdClass ;
10+ $ m [] = new stdClass ;
11+
12+ foreach ($ m as $ l ) {
13+ unset($ m [0 ]);
14+ unset($ m [0 ]);
15+ }
16+
17+ var_dump ($ m );
18+ ?>
19+ --EXPECTF--
20+ object(SplStack)#%d (%d) {
21+ ["flags":"SplDoublyLinkedList":private]=>
22+ int(6)
23+ ["dllist":"SplDoublyLinkedList":private]=>
24+ array(0) {
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments