mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fix GH-16588: UAF in Observer->serialize
Closes GH-16600.
This commit is contained in:
parent
e0a0e216a9
commit
144d2ee29a
3 changed files with 31 additions and 1 deletions
1
NEWS
1
NEWS
|
@ -102,6 +102,7 @@ PHP NEWS
|
||||||
(ilutov)
|
(ilutov)
|
||||||
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
|
. Fixed bug GH-16479 (Use-after-free in SplObjectStorage::setInfo()). (ilutov)
|
||||||
. Fixed bug GH-16478 (Use-after-free in SplFixedArray::unset()). (ilutov)
|
. Fixed bug GH-16478 (Use-after-free in SplFixedArray::unset()). (ilutov)
|
||||||
|
. Fixed bug GH-16588 (UAF in Observer->serialize). (nielsdos)
|
||||||
|
|
||||||
- Standard:
|
- Standard:
|
||||||
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
|
. Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
|
||||||
|
|
|
@ -797,11 +797,18 @@ PHP_METHOD(SplObjectStorage, serialize)
|
||||||
RETURN_NULL();
|
RETURN_NULL();
|
||||||
}
|
}
|
||||||
ZVAL_OBJ(&obj, element->obj);
|
ZVAL_OBJ(&obj, element->obj);
|
||||||
|
|
||||||
|
/* Protect against modification; we need a full copy because the data may be refcounted. */
|
||||||
|
zval inf_copy;
|
||||||
|
ZVAL_COPY(&inf_copy, &element->inf);
|
||||||
|
|
||||||
php_var_serialize(&buf, &obj, &var_hash);
|
php_var_serialize(&buf, &obj, &var_hash);
|
||||||
smart_str_appendc(&buf, ',');
|
smart_str_appendc(&buf, ',');
|
||||||
php_var_serialize(&buf, &element->inf, &var_hash);
|
php_var_serialize(&buf, &inf_copy, &var_hash);
|
||||||
smart_str_appendc(&buf, ';');
|
smart_str_appendc(&buf, ';');
|
||||||
zend_hash_move_forward_ex(&intern->storage, &pos);
|
zend_hash_move_forward_ex(&intern->storage, &pos);
|
||||||
|
|
||||||
|
zval_ptr_dtor(&inf_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* members */
|
/* members */
|
||||||
|
|
22
ext/spl/tests/gh16588.phpt
Normal file
22
ext/spl/tests/gh16588.phpt
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
--TEST--
|
||||||
|
GH-16588 (UAF in Observer->serialize)
|
||||||
|
--CREDITS--
|
||||||
|
chibinz
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class C {
|
||||||
|
function __serialize(): array {
|
||||||
|
global $store;
|
||||||
|
$store->removeAll($store);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$store = new SplObjectStorage;
|
||||||
|
$store[new C] = new stdClass;
|
||||||
|
var_dump($store->serialize());
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(47) "x:i:1;O:1:"C":0:{},O:8:"stdClass":0:{};m:a:0:{}"
|
Loading…
Add table
Add a link
Reference in a new issue