Skip to content

Commit 60f6235

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79151
2 parents 2b5fb76 + 3f020ae commit 60f6235

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

ext/spl/spl_dllist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static void spl_ptr_llist_pop(spl_ptr_llist *llist, zval *ret) /* {{{ */
255255
llist->count--;
256256
ZVAL_COPY(ret, &tail->data);
257257

258+
tail->prev = NULL;
258259
if (llist->dtor) {
259260
llist->dtor(tail);
260261
}
@@ -308,6 +309,7 @@ static void spl_ptr_llist_shift(spl_ptr_llist *llist, zval *ret) /* {{{ */
308309
llist->count--;
309310
ZVAL_COPY(ret, &head->data);
310311

312+
head->next = NULL;
311313
if (llist->dtor) {
312314
llist->dtor(head);
313315
}

ext/spl/tests/bug79151.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #79151: heap use after free caused by spl_dllist_it_helper_move_forward
3+
--FILE--
4+
<?php
5+
6+
$a = new SplDoublyLinkedList();
7+
$a->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_DELETE);
8+
$a->push(1);
9+
$a->rewind();
10+
$a->unshift(2);
11+
var_dump($a->pop());
12+
var_dump($a->next());
13+
14+
$a = new SplDoublyLinkedList();
15+
$a->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_DELETE);
16+
$a->unshift(1);
17+
$a->rewind();
18+
$a->push(2);
19+
var_dump($a->shift());
20+
var_dump($a->next());
21+
22+
?>
23+
--EXPECT--
24+
int(1)
25+
NULL
26+
int(1)
27+
NULL

0 commit comments

Comments
 (0)