From 1c3b44b320982e7b5d9cb44d893aa72cce4016ed Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 8 Mar 2009 17:28:39 +0000 Subject: [PATCH] - MFH: Fixed bug #47593 (interface_exists() returns false when using absolute namespace path) patch by Kalle - BFN #47572 --- NEWS | 3 +++ Zend/tests/bug47593.phpt | 34 ++++++++++++++++++++++++++++++++++ Zend/zend_builtin_functions.c | 22 ++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/bug47593.phpt diff --git a/NEWS b/NEWS index 7bd100b624..9371a042a3 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ PHP NEWS - Re-enabled phar for big-endian systems after fixing problems. (Greg) +- Fixed bug #47593 (interface_exists() returns false when using absolute + namespace path). (Kalle, Felipe) +- Fixed bug #47572 (Undefined constant causes segmentation fault). (Felipe) - Fixed bug #47549 (get_defined_constants() return array with broken array categories). (Ilia) - Fixed Bug #47443 (metaphone('scratch') returns wrong result). (Felipe) diff --git a/Zend/tests/bug47593.phpt b/Zend/tests/bug47593.phpt new file mode 100644 index 0000000000..98aa19a91c --- /dev/null +++ b/Zend/tests/bug47593.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #47593 (interface_exists() returns false when using absolute namespace path) +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +int(11) +bool(true) +bool(false) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index f7d0dc9960..3dbd080510 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1228,10 +1228,21 @@ ZEND_FUNCTION(interface_exists) } if (!autoload) { + char *name; + int len; + lc_name = do_alloca(iface_name_len + 1, use_heap); zend_str_tolower_copy(lc_name, iface_name, iface_name_len); - found = zend_hash_find(EG(class_table), lc_name, iface_name_len+1, (void **) &ce); + /* Ignore leading "\" */ + name = lc_name; + len = iface_name_len; + if (lc_name[0] == '\\') { + name = &lc_name[1]; + len--; + } + + found = zend_hash_find(EG(class_table), name, len+1, (void **) &ce); free_alloca(lc_name, use_heap); RETURN_BOOL(found == SUCCESS && (*ce)->ce_flags & ZEND_ACC_INTERFACE); } @@ -1260,8 +1271,15 @@ ZEND_FUNCTION(function_exists) } lcname = zend_str_tolower_dup(name, name_len); + + /* Ignore leading "\" */ + name = lcname; + if (lcname[0] == '\\') { + name = &lcname[1]; + name_len--; + } - retval = (zend_hash_find(EG(function_table), lcname, name_len+1, (void **)&func) == SUCCESS); + retval = (zend_hash_find(EG(function_table), name, name_len+1, (void **)&func) == SUCCESS); efree(lcname); -- 2.40.0