]> granicus.if.org Git - php/commitdiff
Fixed bug #44827 (define() allows :: in constant names).
authorIlia Alshanetsky <iliaa@php.net>
Wed, 30 Dec 2009 19:15:11 +0000 (19:15 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 30 Dec 2009 19:15:11 +0000 (19:15 +0000)
Zend/zend_builtin_functions.c

index 00c235c8b6169e96311577eae9f0b0c39d5e4041..322f186583f7743693dc0dbba89bcd829fe0cff2 100644 (file)
@@ -623,12 +623,25 @@ ZEND_FUNCTION(define)
        zend_bool non_cs = 0;
        int case_sensitive = CONST_CS;
        zend_constant c;
+       void *found = NULL;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "tz|b", &name, &name_len, &name_type, &val, &non_cs) == FAILURE) {
                return;
        }
 
-       if(non_cs) {
+       if (name_type == IS_UNICODE) {
+               UChar *sep = USTR_MAKE("::");
+               found = zend_u_memnstr(name.u, sep, sizeof("::") - 1, name.u + name_len);
+               efree(sep);
+       } else {
+               found = zend_memnstr(name.s, "::", sizeof("::") - 1, name.s + name_len);
+       }
+       if (found) {
+               zend_error(E_WARNING, "Class constants cannot be defined or redefined");
+               RETURN_FALSE;
+       }
+
+       if (non_cs) {
                case_sensitive = 0;
        }