File tree 3 files changed +32
-1
lines changed 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ PHP NEWS
112
112
. Fixed bug GH-16588 (UAF in Observer->serialize). (nielsdos)
113
113
. Fix GH-16477 (Segmentation fault when calling __debugInfo() after failed
114
114
SplFileObject::__constructor). (Girgias)
115
+ . Fixed bug GH-16589 (UAF in SplDoublyLinked->serialize()). (nielsdos)
115
116
116
117
- Standard:
117
118
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
Original file line number Diff line number Diff line change @@ -44,10 +44,13 @@ PHPAPI zend_class_entry *spl_ce_SplStack;
44
44
efree(elem); \
45
45
}
46
46
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)) { \
48
48
efree(elem); \
49
+ on_free \
49
50
}
50
51
52
+ #define SPL_LLIST_CHECK_DELREF (elem ) SPL_LLIST_CHECK_DELREF_EX(elem, ;)
53
+
51
54
#define SPL_LLIST_ADDREF (elem ) SPL_LLIST_RC(elem)++
52
55
#define SPL_LLIST_CHECK_ADDREF (elem ) if (elem) SPL_LLIST_RC(elem)++
53
56
@@ -1023,8 +1026,12 @@ PHP_METHOD(SplDoublyLinkedList, serialize)
1023
1026
smart_str_appendc (& buf , ':' );
1024
1027
next = current -> next ;
1025
1028
1029
+ SPL_LLIST_CHECK_ADDREF (next );
1030
+
1026
1031
php_var_serialize (& buf , & current -> data , & var_hash );
1027
1032
1033
+ SPL_LLIST_CHECK_DELREF_EX (next , break ;);
1034
+
1028
1035
current = next ;
1029
1036
}
1030
1037
Original file line number Diff line number Diff line change
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:{}"
You can’t perform that action at this time.
0 commit comments