mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-16589: UAF in SplDoublyLinked->serialize()
This commit is contained in:
commit
d9947e8c42
3 changed files with 32 additions and 1 deletions
1
NEWS
1
NEWS
|
@ -112,6 +112,7 @@ PHP NEWS
|
|||
. Fixed bug GH-16588 (UAF in Observer->serialize). (nielsdos)
|
||||
. Fix GH-16477 (Segmentation fault when calling __debugInfo() after failed
|
||||
SplFileObject::__constructor). (Girgias)
|
||||
. Fixed bug GH-16589 (UAF in SplDoublyLinked->serialize()). (nielsdos)
|
||||
|
||||
- Standard:
|
||||
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
|
||||
|
|
|
@ -44,10 +44,13 @@ PHPAPI zend_class_entry *spl_ce_SplStack;
|
|||
efree(elem); \
|
||||
}
|
||||
|
||||
#define SPL_LLIST_CHECK_DELREF(elem) if ((elem) && !--SPL_LLIST_RC(elem)) { \
|
||||
#define SPL_LLIST_CHECK_DELREF_EX(elem, on_free) if ((elem) && !--SPL_LLIST_RC(elem)) { \
|
||||
efree(elem); \
|
||||
on_free \
|
||||
}
|
||||
|
||||
#define SPL_LLIST_CHECK_DELREF(elem) SPL_LLIST_CHECK_DELREF_EX(elem, ;)
|
||||
|
||||
#define SPL_LLIST_ADDREF(elem) SPL_LLIST_RC(elem)++
|
||||
#define SPL_LLIST_CHECK_ADDREF(elem) if (elem) SPL_LLIST_RC(elem)++
|
||||
|
||||
|
@ -1023,8 +1026,12 @@ PHP_METHOD(SplDoublyLinkedList, serialize)
|
|||
smart_str_appendc(&buf, ':');
|
||||
next = current->next;
|
||||
|
||||
SPL_LLIST_CHECK_ADDREF(next);
|
||||
|
||||
php_var_serialize(&buf, ¤t->data, &var_hash);
|
||||
|
||||
SPL_LLIST_CHECK_DELREF_EX(next, break;);
|
||||
|
||||
current = next;
|
||||
}
|
||||
|
||||
|
|
23
ext/spl/tests/gh16589.phpt
Normal file
23
ext/spl/tests/gh16589.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--TEST--
|
||||
GH-16589 (UAF in SplDoublyLinked->serialize())
|
||||
--CREDITS--
|
||||
chibinz
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class C {
|
||||
function __serialize(): array {
|
||||
global $list;
|
||||
$list->pop();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
$list = new SplDoublyLinkedList;
|
||||
$list->add(0, new C);
|
||||
$list->add(1, 1);
|
||||
var_dump($list->serialize());
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
string(17) "i:0;:O:1:"C":0:{}"
|
Loading…
Add table
Add a link
Reference in a new issue