Skip to content

Commit d9947e8

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix phpGH-16589: UAF in SplDoublyLinked->serialize()
2 parents 5605285 + 8f60309 commit d9947e8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ PHP NEWS
112112
. Fixed bug GH-16588 (UAF in Observer->serialize). (nielsdos)
113113
. Fix GH-16477 (Segmentation fault when calling __debugInfo() after failed
114114
SplFileObject::__constructor). (Girgias)
115+
. Fixed bug GH-16589 (UAF in SplDoublyLinked->serialize()). (nielsdos)
115116

116117
- Standard:
117118
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with

ext/spl/spl_dllist.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ PHPAPI zend_class_entry *spl_ce_SplStack;
4444
efree(elem); \
4545
}
4646

47-
#define SPL_LLIST_CHECK_DELREF(elem) if ((elem) && !--SPL_LLIST_RC(elem)) { \
47+
#define SPL_LLIST_CHECK_DELREF_EX(elem, on_free) if ((elem) && !--SPL_LLIST_RC(elem)) { \
4848
efree(elem); \
49+
on_free \
4950
}
5051

52+
#define SPL_LLIST_CHECK_DELREF(elem) SPL_LLIST_CHECK_DELREF_EX(elem, ;)
53+
5154
#define SPL_LLIST_ADDREF(elem) SPL_LLIST_RC(elem)++
5255
#define SPL_LLIST_CHECK_ADDREF(elem) if (elem) SPL_LLIST_RC(elem)++
5356

@@ -1023,8 +1026,12 @@ PHP_METHOD(SplDoublyLinkedList, serialize)
10231026
smart_str_appendc(&buf, ':');
10241027
next = current->next;
10251028

1029+
SPL_LLIST_CHECK_ADDREF(next);
1030+
10261031
php_var_serialize(&buf, &current->data, &var_hash);
10271032

1033+
SPL_LLIST_CHECK_DELREF_EX(next, break;);
1034+
10281035
current = next;
10291036
}
10301037

ext/spl/tests/gh16589.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-16589 (UAF in SplDoublyLinked->serialize())
3+
--CREDITS--
4+
chibinz
5+
--FILE--
6+
<?php
7+
8+
class C {
9+
function __serialize(): array {
10+
global $list;
11+
$list->pop();
12+
return [];
13+
}
14+
}
15+
16+
$list = new SplDoublyLinkedList;
17+
$list->add(0, new C);
18+
$list->add(1, 1);
19+
var_dump($list->serialize());
20+
21+
?>
22+
--EXPECT--
23+
string(17) "i:0;:O:1:"C":0:{}"

0 commit comments

Comments
 (0)