]> granicus.if.org Git - php/commitdiff
Fix usage of casted string in ReflectionParameter ctor
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 24 Nov 2020 15:41:18 +0000 (16:41 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 24 Nov 2020 15:42:16 +0000 (16:42 +0100)
Fixes oss-fuzz #27755.

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

index 620d95afa49e8441f52fb74f78cde81c58c3983a..6384e2b4104edba4c607c4bcd6e720d71a34154f 100644 (file)
@@ -2306,10 +2306,10 @@ ZEND_METHOD(reflection_parameter, __construct)
                                        /* nothing to do. don't set is_closure since is the invoke handler,
                                           not the closure itself */
                                } else if ((fptr = zend_hash_find_ptr(&ce->function_table, lcname)) == NULL) {
+                                       zend_throw_exception_ex(reflection_exception_ptr, 0,
+                                               "Method %s::%s() does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
                                        zend_string_release(name);
                                        zend_string_release(lcname);
-                                       zend_throw_exception_ex(reflection_exception_ptr, 0,
-                                               "Method %s::%s() does not exist", ZSTR_VAL(ce->name), Z_STRVAL_P(method));
                                        return;
                                }
                                zend_string_release(name);
diff --git a/ext/reflection/tests/ReflectionParameter_ctor_cast.phpt b/ext/reflection/tests/ReflectionParameter_ctor_cast.phpt
new file mode 100644 (file)
index 0000000..10f4564
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Test method name string cast in ReflectionParameter ctor
+--FILE--
+<?php
+
+class A {}
+try {
+    new ReflectionParameter([
+        A::class,
+        new class { public function __toString() { return 'method'; } }
+    ], 'param');
+} catch (ReflectionException $e) {
+    echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Method A::method() does not exist