]> granicus.if.org Git - php/commitdiff
Fixed bug #80370: Segmentation fault reflecting attributes of dynamic property
authorBenjamin Eberlei <kontakt@beberlei.de>
Sun, 15 Nov 2020 07:45:26 +0000 (08:45 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 17 Nov 2020 09:54:27 +0000 (10:54 +0100)
Closes GH-6428.

NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug80370.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index d22439251f36ad6655c61ea94032dbacf1a0ac0f..98849b8a435e5d086269127007eb4053070e2df3 100644 (file)
--- 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:
index 2be0ab98db6565b6130de2b2b56961e30f0d1b73..114b2c273ff19362cf7144a260a52ec7a6efdfc8 100644 (file)
@@ -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 (file)
index 0000000..41d01c2
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Bug #80370: Segfault on ReflectionProperty::getAttributes of dynamic property
+--FILE--
+<?php
+class Foobar {
+
+}
+
+$foobar = new Foobar();
+$foobar->bar = 42;
+
+$reflectionObject = new ReflectionObject($foobar);
+$reflectionProperty = $reflectionObject->getProperty('bar');
+var_dump($reflectionProperty->getAttributes());
+--EXPECT--
+array(0) {
+}