mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Add missing scope check for readonly prop initialization
If the initializing assignment is an array append we will go through the UNDEF codepath of get_property_ptr_ptr, which did not verify that the initialization scope is valid.
This commit is contained in:
parent
5a1ab2c9b3
commit
4796183958
36
Zend/tests/readonly_props/array_append_initialization.phpt
Normal file
36
Zend/tests/readonly_props/array_append_initialization.phpt
Normal file
@ -0,0 +1,36 @@
|
||||
--TEST--
|
||||
Use array append as initialization
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class C {
|
||||
public readonly array $a;
|
||||
|
||||
public function init() {
|
||||
$this->a[] = 1;
|
||||
var_dump($this->a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function init() {
|
||||
$c = new C;
|
||||
$c->a[] = 1;
|
||||
var_dump($c->a);
|
||||
}
|
||||
|
||||
(new C)->init();
|
||||
|
||||
try {
|
||||
init();
|
||||
} catch (Error $e) {
|
||||
echo $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
Cannot initialize readonly property C::$a from global scope
|
@ -1020,6 +1020,9 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
|
||||
ZVAL_NULL(retval);
|
||||
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
|
||||
}
|
||||
} else if (prop_info && UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)
|
||||
&& !verify_readonly_initialization_access(prop_info, zobj->ce, name, "initialize")) {
|
||||
retval = &EG(error_zval);
|
||||
}
|
||||
} else {
|
||||
/* we do have getter - fail and let it try again with usual get/set */
|
||||
|
Loading…
Reference in New Issue
Block a user