From 71efa5b435f032b3a88204d8771b4f83869bec26 Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Mon, 10 Jul 2006 00:18:53 +0000 Subject: [PATCH] - MFH Fixed bug #37816 (ReflectionProperty does not throw exception when accessing protected attribute) --- NEWS | 2 ++ ext/reflection/php_reflection.c | 26 +++++++++++++++----------- ext/reflection/tests/bug37816.phpt | 28 ++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100755 ext/reflection/tests/bug37816.phpt diff --git a/NEWS b/NEWS index ae0aea4b7c..6a7ca088a3 100644 --- a/NEWS +++ b/NEWS @@ -91,6 +91,8 @@ PHP NEWS - Fixed bug #37864 (file_get_contents() leaks on empty file). (Hannes) - Fixed bug #37862 (Integer pointer comparison to numeric value). (bugs-php at thewrittenword dot com) +- Fixed bug #37816 (ReflectionProperty does not throw exception when accessing + protected attribute). (Marcus) - Fixed bug #37811 (define not using toString on objects). (Marcus) - Fixed bug #37807 (segmentation fault during SOAP schema import). (Tony) - Fixed bug #37806 (weird behavior of object type and comparison). (Marcus) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a223889a68..de1b6435e9 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3838,23 +3838,24 @@ ZEND_METHOD(reflection_property, getValue) { reflection_object *intern; property_reference *ref; - zval *object; + zval *object, name; zval **member= NULL; METHOD_NOTSTATIC(reflection_property_ptr); GET_REFLECTION_OBJECT_PTR(ref); -#if MBO_0 if (!(ref->prop->flags & ZEND_ACC_PUBLIC)) { - _DO_THROW("Cannot access non-public member"); - /* Returns from this function */ + _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); + zval_dtor(&name); + return; } -#endif if ((ref->prop->flags & ZEND_ACC_STATIC)) { zend_update_class_constants(intern->ce TSRMLS_CC); if (zend_hash_quick_find(CE_STATIC_MEMBERS(intern->ce), ref->prop->name, ref->prop->name_length + 1, ref->prop->h, (void **) &member) == FAILURE) { - zend_error(E_ERROR, "Internal error: Could not find the property %s", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop->name); /* Bails out */ } } else { @@ -3862,7 +3863,7 @@ ZEND_METHOD(reflection_property, getValue) return; } if (zend_hash_quick_find(Z_OBJPROP_P(object), ref->prop->name, ref->prop->name_length + 1, ref->prop->h, (void **) &member) == FAILURE) { - zend_error(E_ERROR, "Internal error: Could not find the property %s", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop->name); /* Bails out */ } } @@ -3880,7 +3881,7 @@ ZEND_METHOD(reflection_property, setValue) reflection_object *intern; property_reference *ref; zval **variable_ptr; - zval *object; + zval *object, name; zval *value; int setter_done = 0; zval *tmp; @@ -3890,8 +3891,11 @@ ZEND_METHOD(reflection_property, setValue) GET_REFLECTION_OBJECT_PTR(ref); if (!(ref->prop->flags & ZEND_ACC_PUBLIC)) { - _DO_THROW("Cannot access non-public member"); - /* Returns from this function */ + _default_get_entry(getThis(), "name", sizeof("name"), &name TSRMLS_CC); + zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, + "Cannot access non-public member %s::%s", intern->ce->name, Z_STRVAL(name)); + zval_dtor(&name); + return; } if ((ref->prop->flags & ZEND_ACC_STATIC)) { @@ -3910,7 +3914,7 @@ ZEND_METHOD(reflection_property, setValue) } if (zend_hash_quick_find(prop_table, ref->prop->name, ref->prop->name_length + 1, ref->prop->h, (void **) &variable_ptr) == FAILURE) { - zend_error(E_ERROR, "Internal error: Could not find the property %s", ref->prop->name); + zend_error(E_ERROR, "Internal error: Could not find the property %s::%s", intern->ce->name, ref->prop->name); /* Bails out */ } if (*variable_ptr == value) { diff --git a/ext/reflection/tests/bug37816.phpt b/ext/reflection/tests/bug37816.phpt new file mode 100755 index 0000000000..18a49046dc --- /dev/null +++ b/ext/reflection/tests/bug37816.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #37816 (ReflectionProperty does not throw exception when accessing protected attribute) +--FILE-- +getValue($o); +} +catch (Exception $e) +{ + echo 'Caught: ' . $e->getMessage() . "\n"; +} + +?> +===DONE=== +--EXPECTF-- +Caught: Cannot access non-public member TestClass::p +===DONE=== -- 2.40.0