File tree 3 files changed +31
-1
lines changed
3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,7 @@ PHP NEWS
109
109
(ilutov)
110
110
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
111
111
. Fixed bug GH-16478 (Use-after-free in SplFixedArray::unset()). (ilutov)
112
+ . Fixed bug GH-16588 (UAF in Observer->serialize). (nielsdos)
112
113
113
114
- Standard:
114
115
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
Original file line number Diff line number Diff line change @@ -795,11 +795,18 @@ PHP_METHOD(SplObjectStorage, serialize)
795
795
RETURN_NULL ();
796
796
}
797
797
ZVAL_OBJ (& obj , element -> obj );
798
+
799
+ /* Protect against modification; we need a full copy because the data may be refcounted. */
800
+ zval inf_copy ;
801
+ ZVAL_COPY (& inf_copy , & element -> inf );
802
+
798
803
php_var_serialize (& buf , & obj , & var_hash );
799
804
smart_str_appendc (& buf , ',' );
800
- php_var_serialize (& buf , & element -> inf , & var_hash );
805
+ php_var_serialize (& buf , & inf_copy , & var_hash );
801
806
smart_str_appendc (& buf , ';' );
802
807
zend_hash_move_forward_ex (& intern -> storage , & pos );
808
+
809
+ zval_ptr_dtor (& inf_copy );
803
810
}
804
811
805
812
/* members */
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-16588 (UAF in Observer->serialize)
3
+ --CREDITS--
4
+ chibinz
5
+ --FILE--
6
+ <?php
7
+
8
+ class C {
9
+ function __serialize (): array {
10
+ global $ store ;
11
+ $ store ->removeAll ($ store );
12
+ return [];
13
+ }
14
+ }
15
+
16
+ $ store = new SplObjectStorage ;
17
+ $ store [new C ] = new stdClass ;
18
+ var_dump ($ store ->serialize ());
19
+
20
+ ?>
21
+ --EXPECT--
22
+ string(47) "x:i:1;O:1:"C":0:{},O:8:"stdClass":0:{};m:a:0:{}"
You can’t perform that action at this time.
0 commit comments