Skip to content

Commit 215ebbb

Browse files
authored
zend_API: Do not overwrite readonly properties in object_properties_load() (#19767)
Fixes #19765.
1 parent d2fa1ca commit 215ebbb

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PHP NEWS
1414
. Fixed bug GH-19681 (PHP_EXPAND_PATH broken with bash 5.3.0). (Remi)
1515
. Fixed bug GH-19720 (Assertion failure when error handler throws when
1616
accessing a deprecated constant). (nielsdos)
17+
. Fixed bug GH-19765 (object_properties_load() bypasses readonly property
18+
checks). (timwolla)
1719

1820
- CLI:
1921
. Fixed bug GH-19461 (Improve error message on listening error with IPv6

Zend/zend_API.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,14 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
17011701
property_info &&
17021702
(property_info->flags & ZEND_ACC_STATIC) == 0) {
17031703
zval *slot = OBJ_PROP(object, property_info->offset);
1704+
if (UNEXPECTED((property_info->flags & ZEND_ACC_READONLY) && !Z_ISUNDEF_P(slot))) {
1705+
if (Z_PROP_FLAG_P(slot) & IS_PROP_REINITABLE) {
1706+
Z_PROP_FLAG_P(slot) &= ~IS_PROP_REINITABLE;
1707+
} else {
1708+
zend_readonly_property_modification_error(property_info);
1709+
return;
1710+
}
1711+
}
17041712
zval_ptr_dtor(slot);
17051713
ZVAL_COPY_VALUE(slot, prop);
17061714
zval_add_ref(slot);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-19765: object_properties_load() bypasses readonly property checks
3+
--FILE--
4+
<?php
5+
6+
use Random\Engine\Mt19937;
7+
use Random\Engine\PcgOneseq128XslRr64;
8+
use Random\Randomizer;
9+
10+
try {
11+
$r = new Randomizer(new Mt19937());
12+
$r->__unserialize([['engine' => new PcgOneseq128XslRr64()]]);
13+
} catch (Exception $error) {
14+
echo $error->getMessage() . "\n";
15+
}
16+
var_dump($r->engine::class);
17+
18+
?>
19+
--EXPECT--
20+
Invalid serialization data for Random\Randomizer object
21+
string(21) "Random\Engine\Mt19937"

ext/random/tests/03_randomizer/gh_9186_unserialize.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Fix GH-9186 @strict-properties can be bypassed using unserialization
2+
GH-9186: @strict-properties can be bypassed using unserialization
33
--FILE--
44
<?php
55

0 commit comments

Comments
 (0)