Skip to content

Fix uaf in SplDoublyLinkedList::offsetSet() #16466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Zend/tests/gh16464.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
GH-16464: Use-after-free in SplDoublyLinkedList::offsetSet() when modifying list in destructor of overwritten object
--FILE--
<?php

class C {
public $a;

function __destruct() {
global $list;
var_dump($list->pop());
}
}

$list = new SplDoublyLinkedList;
$list->add(0, new C);
$list[0] = 42;
var_dump($list);

?>
--EXPECTF--
int(42)
object(SplDoublyLinkedList)#%d (2) {
["flags":"SplDoublyLinkedList":private]=>
int(0)
["dllist":"SplDoublyLinkedList":private]=>
array(0) {
}
}
4 changes: 3 additions & 1 deletion ext/spl/spl_dllist.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,10 @@ PHP_METHOD(SplDoublyLinkedList, offsetSet)
if (element != NULL) {
/* the element is replaced, delref the old one as in
* SplDoublyLinkedList::pop() */
zval_ptr_dtor(&element->data);
zval garbage;
ZVAL_COPY_VALUE(&garbage, &element->data);
ZVAL_COPY(&element->data, value);
zval_ptr_dtor(&garbage);
} else {
zval_ptr_dtor(value);
zend_argument_error(spl_ce_OutOfRangeException, 1, "is an invalid offset");
Expand Down
Loading