File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed
Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -728,11 +728,10 @@ PHP_METHOD(SplDoublyLinkedList, offsetUnset)
728728 element = spl_ptr_llist_offset (intern -> llist , index , intern -> flags & SPL_DLLIST_IT_LIFO );
729729
730730 if (element != NULL ) {
731- /* connect the neighbors */
731+ /* disconnect the neighbours */
732732 if (element -> prev ) {
733733 element -> prev -> next = element -> next ;
734734 }
735-
736735 if (element -> next ) {
737736 element -> next -> prev = element -> prev ;
738737 }
@@ -746,6 +745,10 @@ PHP_METHOD(SplDoublyLinkedList, offsetUnset)
746745 llist -> tail = element -> prev ;
747746 }
748747
748+ /* Keep consistency if element is kept alive. */
749+ element -> prev = NULL ;
750+ element -> next = NULL ;
751+
749752 /* finally, delete the element */
750753 llist -> count -- ;
751754
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