From: Benjamin Eberlei Date: Sun, 15 Nov 2020 07:45:26 +0000 (+0100) Subject: Fixed bug #80370: Segmentation fault reflecting attributes of dynamic property X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1727d96d0e1057ce140682b79d7f121dee0fc370;p=php Fixed bug #80370: Segmentation fault reflecting attributes of dynamic property Closes GH-6428. --- diff --git a/NEWS b/NEWS index d22439251f..98849b8a43 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ PHP NEWS . Fixed bug #74558 (Can't rebind closure returned by Closure::fromCallable()). (cmb) +- Reflection: + . Fixed bug #80370 (getAttributes segfault on dynamic properties). (Benjamin + Eberlei) + 12 Nov 2020, PHP 8.0.0RC4 - Core: diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 2be0ab98db..114b2c273f 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5498,6 +5498,10 @@ ZEND_METHOD(ReflectionProperty, getAttributes) GET_REFLECTION_OBJECT_PTR(ref); + if (ref->prop == NULL) { + RETURN_EMPTY_ARRAY(); + } + reflect_attributes(INTERNAL_FUNCTION_PARAM_PASSTHRU, ref->prop->attributes, 0, ref->prop->ce, ZEND_ATTRIBUTE_TARGET_PROPERTY, ref->prop->ce->type == ZEND_USER_CLASS ? ref->prop->ce->info.user.filename : NULL); diff --git a/ext/reflection/tests/bug80370.phpt b/ext/reflection/tests/bug80370.phpt new file mode 100644 index 0000000000..41d01c2e7e --- /dev/null +++ b/ext/reflection/tests/bug80370.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #80370: Segfault on ReflectionProperty::getAttributes of dynamic property +--FILE-- +bar = 42; + +$reflectionObject = new ReflectionObject($foobar); +$reflectionProperty = $reflectionObject->getProperty('bar'); +var_dump($reflectionProperty->getAttributes()); +--EXPECT-- +array(0) { +}