]> granicus.if.org Git - php/commitdiff
merge r292823 Fixed bug #44827 (define() allows :: in constant names). (iliaa)
authorJohannes Schlüter <johannes@php.net>
Mon, 25 Jan 2010 23:41:18 +0000 (23:41 +0000)
committerJohannes Schlüter <johannes@php.net>
Mon, 25 Jan 2010 23:41:18 +0000 (23:41 +0000)
and r293974 Added test case for bug #44827 (iliaa)

NEWS
Zend/tests/bug44827.phpt [new file with mode: 0644]
Zend/zend_builtin_functions.c

diff --git a/NEWS b/NEWS
index 6343bf04ffee9adfac1c03d82e3df914d9c28920..eaed0270c962e638828a036ba93bec3a185217c6 100644 (file)
--- 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 (file)
index 0000000..a9f1d87
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #44827 (define() allows :: in constant names)
+--FILE--
+<?php
+define('foo::bar', 1);
+define('::', 1);
+?>
+--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
index c19f3706665ccaa03c66f53bc4e412e3a33f8bf1..a001c6c7e509e202529204550274524cb683d387 100644 (file)
@@ -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: