Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ext/spl/spl_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,18 @@ PHP_METHOD(SplObjectStorage, serialize)
RETURN_NULL();
}
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);
smart_str_appendc(&buf, ',');
php_var_serialize(&buf, &element->inf, &var_hash);
php_var_serialize(&buf, &inf_copy, &var_hash);
smart_str_appendc(&buf, ';');
zend_hash_move_forward_ex(&intern->storage, &pos);

zval_ptr_dtor(&inf_copy);
}

/* members */
Expand Down
22 changes: 22 additions & 0 deletions ext/spl/tests/gh16588.phpt
Original file line number Diff line number Diff line change
@@ -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