From: Ilia Alshanetsky Date: Tue, 3 Mar 2009 23:43:06 +0000 (+0000) Subject: MFB: Fixed bug #47549 (get_defined_constants() return array with broken X-Git-Tag: php-5.4.0alpha1~191^2~4200 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=788c8bbadac21317de534d67af11b5279736ba66;p=php MFB: Fixed bug #47549 (get_defined_constants() return array with broken array categories) --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index f976c7500b..354fc9c6c8 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -25,6 +25,7 @@ #include "zend_constants.h" #include "zend_ini.h" #include "zend_extensions.h" +#include #undef ZEND_TEST_EXCEPTIONS @@ -626,6 +627,40 @@ ZEND_FUNCTION(define) return; } + /* check if class constant */ + if ((p = memchr(name, ':', name_len))) { + char *s = name; + zend_class_entry **ce; + + if (*(p + 1) != ':') { /* invalid constant specifier */ + RETURN_FALSE; + } else if ((p + 2) >= (name + name_len)) { /* constant name length < 1 */ + zend_error(E_WARNING, "Constants name cannot be empty"); + RETURN_FALSE; + } else if (zend_lookup_class(s, (p - s), &ce TSRMLS_CC) != SUCCESS) { /* invalid class name */ + zend_error(E_WARNING, "Class does not exists"); + RETURN_FALSE; + } else { /* check of constant name contains invalid chars */ + int ok = 1; + p += 2; /* move beyond :: to 1st char of constant's name */ + + if (!isalpha(*p) && *p != '_') { + ok = 0; + } + + while (ok && *++p) { + if (!isalnum(*p) && *p != '_') { + ok = 0; + break; + } + } + + if (!ok) { + RETURN_FALSE; + } + } + } + if(non_cs) { case_sensitive = 0; } @@ -1885,7 +1920,8 @@ ZEND_FUNCTION(get_defined_constants) module_names[0] = "internal"; zend_hash_internal_pointer_reset_ex(&module_registry, &pos); while (zend_hash_get_current_data_ex(&module_registry, (void *) &module, &pos) != FAILURE) { - module_names[i++] = (char*)module->name; + module_names[module->module_number] = (char *)module->name; + i++; zend_hash_move_forward_ex(&module_registry, &pos); } module_names[i] = "user";