From: Johannes Schlüter Date: Mon, 25 Jan 2010 23:41:18 +0000 (+0000) Subject: merge r292823 Fixed bug #44827 (define() allows :: in constant names). (iliaa) X-Git-Tag: php-5.3.2RC2~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f61ee70de6bd24f08bf63976856997f540e31409;p=php merge r292823 Fixed bug #44827 (define() allows :: in constant names). (iliaa) and r293974 Added test case for bug #44827 (iliaa) --- diff --git a/NEWS b/NEWS index 6343bf04ff..eaed0270c9 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ PHP NEWS in HTTP uploads). (Ilia) - Fixed bug #47409 (extract() problem with array containing word "this"). (Ilia, chrisstocktonaz at gmail dot com) +- Fixed bug #44827 (define() allows :: in constant names). (Ilia) 22 Dec 2009, PHP 5.3.2 RC 1 diff --git a/Zend/tests/bug44827.phpt b/Zend/tests/bug44827.phpt new file mode 100644 index 0000000000..a9f1d87d24 --- /dev/null +++ b/Zend/tests/bug44827.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #44827 (define() allows :: in constant names) +--FILE-- + +--EXPECTF-- +Warning: Class constants cannot be defined or redefined in %sbug44827.php on line %d + +Warning: Class constants cannot be defined or redefined in %sbug44827.php on line %d diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index c19f370666..a001c6c7e5 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -629,7 +629,6 @@ ZEND_FUNCTION(define) zend_bool non_cs = 0; int case_sensitive = CONST_CS; zend_constant c; - char *p; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|b", &name, &name_len, &val, &non_cs) == FAILURE) { return; @@ -640,31 +639,9 @@ ZEND_FUNCTION(define) } /* class constant, check if there is name and make sure class is valid & exists */ - if ((p = zend_memnstr(name, "::", sizeof("::") - 1, name + name_len))) { - char *class_name; - int found; - zend_class_entry **ce; - ALLOCA_FLAG(use_heap) - - if (p == (name + name_len - sizeof("::") + 1)) { - zend_error(E_WARNING, "Class constant must have a name"); - RETURN_FALSE; - } else if (p == name) { - zend_error(E_WARNING, "Missing class name"); - RETURN_FALSE; - } - - class_name = do_alloca((p - name + 1), use_heap); - zend_str_tolower_copy(class_name, name, (p - name)); - - found = zend_hash_find(EG(class_table), class_name, p - name + 1, (void **) &ce); - - if (found != SUCCESS) { - zend_error(E_WARNING, "Class '%s' does not exist", class_name); - free_alloca(class_name, use_heap); - RETURN_FALSE; - } - free_alloca(class_name, use_heap); + if (zend_memnstr(name, "::", sizeof("::") - 1, name + name_len)) { + zend_error(E_WARNING, "Class constants cannot be defined or redefined"); + RETURN_FALSE; } repeat: