Skip to content

Commit 396b995

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix phpGH-16589: UAF in SplDoublyLinked->serialize()
2 parents e111bf7 + d9947e8 commit 396b995

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
@@ -18,6 +18,7 @@ PHP NEWS
1818
. Fixed bug GH-16588 (UAF in Observer->serialize). (nielsdos)
1919
. Fix GH-16477 (Segmentation fault when calling __debugInfo() after failed
2020
SplFileObject::__constructor). (Girgias)
21+
. Fixed bug GH-16589 (UAF in SplDoublyLinked->serialize()). (nielsdos)
2122

2223
- SysVShm:
2324
. Fixed bug GH-16591 (Assertion error in shm_put_var). (nielsdos, cmb)

ext/spl/spl_dllist.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ PHPAPI zend_class_entry *spl_ce_SplStack;
4141
efree(elem); \
4242
}
4343

44-
#define SPL_LLIST_CHECK_DELREF(elem) if ((elem) && !--SPL_LLIST_RC(elem)) { \
44+
#define SPL_LLIST_CHECK_DELREF_EX(elem, on_free) if ((elem) && !--SPL_LLIST_RC(elem)) { \
4545
efree(elem); \
46+
on_free \
4647
}
4748

49+
#define SPL_LLIST_CHECK_DELREF(elem) SPL_LLIST_CHECK_DELREF_EX(elem, ;)
50+
4851
#define SPL_LLIST_ADDREF(elem) SPL_LLIST_RC(elem)++
4952
#define SPL_LLIST_CHECK_ADDREF(elem) if (elem) SPL_LLIST_RC(elem)++
5053

@@ -1013,8 +1016,12 @@ PHP_METHOD(SplDoublyLinkedList, serialize)
10131016
smart_str_appendc(&buf, ':');
10141017
next = current->next;
10151018

1019+
SPL_LLIST_CHECK_ADDREF(next);
1020+
10161021
php_var_serialize(&buf, &current->data, &var_hash);
10171022

1023+
SPL_LLIST_CHECK_DELREF_EX(next, break;);
1024+
10181025
current = next;
10191026
}
10201027

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)