From aaf0c8b594f1ddcd090123fff3734b0aa1eeccd9 Mon Sep 17 00:00:00 2001 From: Anthony Ferrara Date: Thu, 19 Mar 2015 14:07:03 -0400 Subject: [PATCH] Disallow relative namespace type declarations --- .../scalar_relative_typehint_disallowed.phpt | 2 +- Zend/zend_compile.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt b/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt index 0aea1aedfb..30d2bd8b74 100644 --- a/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt +++ b/Zend/tests/typehints/scalar_relative_typehint_disallowed.phpt @@ -11,4 +11,4 @@ foo(10); ?> --EXPECTF-- -Fatal error: Argument 1 passed to foo() must be an instance of bar\int, integer given, called in %s on line %d and defined in %s on line %d \ No newline at end of file +Fatal error: "bar\int" cannot be used as a type declaration in %s on line %d \ No newline at end of file diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 954412bf19..abdfc3703b 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -146,9 +146,16 @@ static const scalar_typehint_info scalar_typehints[] = { static zend_always_inline const scalar_typehint_info* zend_find_scalar_typehint(const zend_string *const_name) /* {{{ */ { const scalar_typehint_info *info = &scalar_typehints[0]; + const char *uqname; + size_t uqname_len; + + if (!zend_get_unqualified_name(const_name, &uqname, &uqname_len)) { + uqname = const_name->val; + uqname_len = const_name->len; + } while (info->name) { - if (const_name->len == info->name_len && zend_binary_strcasecmp(const_name->val, const_name->len, info->name, info->name_len) == 0) { + if (uqname_len == info->name_len && zend_binary_strcasecmp(uqname, uqname_len, info->name, info->name_len) == 0) { break; } info++; @@ -177,6 +184,9 @@ static zend_always_inline zend_uchar zend_lookup_scalar_typehint_by_name(const z const scalar_typehint_info *info = zend_find_scalar_typehint(const_name); if (info) { + if (const_name->len != info->name_len) { + zend_error_noreturn(E_COMPILE_ERROR, "\"%s\" cannot be used as a type declaration", const_name->val); + } return info->type; } else { return 0; -- 2.50.1