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 @@ -102,6 +102,7 @@ PHP NEWS
102
102
(ilutov)
103
103
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
104
104
. Fixed bug GH-16478 (Use-after-free in SplFixedArray::unset()). (ilutov)
105
+ . Fixed bug GH-16588 (UAF in Observer->serialize). (nielsdos)
105
106
106
107
- Standard:
107
108
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
Original file line number Diff line number Diff line change @@ -797,11 +797,18 @@ PHP_METHOD(SplObjectStorage, serialize)
797
797
RETURN_NULL ();
798
798
}
799
799
ZVAL_OBJ (& obj , element -> obj );
800
+
801
+ /* Protect against modification; we need a full copy because the data may be refcounted. */
802
+ zval inf_copy ;
803
+ ZVAL_COPY (& inf_copy , & element -> inf );
804
+
800
805
php_var_serialize (& buf , & obj , & var_hash );
801
806
smart_str_appendc (& buf , ',' );
802
- php_var_serialize (& buf , & element -> inf , & var_hash );
807
+ php_var_serialize (& buf , & inf_copy , & var_hash );
803
808
smart_str_appendc (& buf , ';' );
804
809
zend_hash_move_forward_ex (& intern -> storage , & pos );
810
+
811
+ zval_ptr_dtor (& inf_copy );
805
812
}
806
813
807
814
/* 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