summaryrefslogtreecommitdiff
path: root/ext/reflection/php_reflection.c
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-04-15 15:15:21 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-06-24 11:17:36 +0200
commit26aefb750a614391cdb8ee3f63d66f46ed57bd55 (patch)
tree71119457730f871261462f4f54dd0e7066027604 /ext/reflection/php_reflection.c
parentef2130db88e3a1038c485eea9708cb2677dc9adc (diff)
downloadphp-git-26aefb750a614391cdb8ee3f63d66f46ed57bd55.tar.gz
Fix #69804: ::getStaticPropertyValue() throws on protected props
`ReflectionClass` allows reading of the values of private and protected constants, and also to get private and protected static methods. Therefore getting the values of private and protected static properties is also permissible, especially since `::getStaticProperties()` already allows to do so. We also allow ::setStaticPropertyValue() to modify private and protected properties, because otherwise this method is useless, as modifying public properties can be done directly.
Diffstat (limited to 'ext/reflection/php_reflection.c')
-rw-r--r--ext/reflection/php_reflection.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index f4d27b580b..c3c29d880b 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -3814,7 +3814,7 @@ ZEND_METHOD(reflection_class, getStaticProperties)
ZEND_METHOD(reflection_class, getStaticPropertyValue)
{
reflection_object *intern;
- zend_class_entry *ce;
+ zend_class_entry *ce, *old_scope;
zend_string *name;
zval *prop, *def_value = NULL;
@@ -3827,7 +3827,12 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue)
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
return;
}
+
+ old_scope = EG(fake_scope);
+ EG(fake_scope) = ce;
prop = zend_std_get_static_property(ce, name, BP_VAR_IS);
+ EG(fake_scope) = old_scope;
+
if (!prop) {
if (def_value) {
ZVAL_COPY(return_value, def_value);
@@ -3847,7 +3852,7 @@ ZEND_METHOD(reflection_class, getStaticPropertyValue)
ZEND_METHOD(reflection_class, setStaticPropertyValue)
{
reflection_object *intern;
- zend_class_entry *ce;
+ zend_class_entry *ce, *old_scope;
zend_property_info *prop_info;
zend_string *name;
zval *variable_ptr, *value;
@@ -3861,7 +3866,10 @@ ZEND_METHOD(reflection_class, setStaticPropertyValue)
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
return;
}
- variable_ptr = zend_std_get_static_property_with_info(ce, name, BP_VAR_W, &prop_info);
+ old_scope = EG(fake_scope);
+ EG(fake_scope) = ce;
+ variable_ptr = zend_std_get_static_property_with_info(ce, name, BP_VAR_W, &prop_info);
+ EG(fake_scope) = old_scope;
if (!variable_ptr) {
zend_clear_exception();
zend_throw_exception_ex(reflection_exception_ptr, 0,