Hi,

On Wed, 2009-12-30 at 19:15 +0000, Ilia Alshanetsky wrote: 
> iliaa                                    Wed, 30 Dec 2009 19:15:11 +0000
> 
> Revision: http://svn.php.net/viewvc?view=revision&revision=292823
> 
> Log:
> Fixed bug #44827 (define() allows :: in constant names).
> 
> Bug: http://bugs.php.net/44827 (Assigned) define('::') can be defined
> 
last time such an issue was reported it was decided to allow to define
"anything". Should we make a special case only for '::'? - Why not '->'
or any other operator?

Last time it was about keywords:
http://devzone.zend.com/article/475-Zend-Weekly-Summaries-Issue-218#Heading3

johannes

On Wed, 2009-12-30 at 19:15 +0000, Ilia Alshanetsky wrote:
> Changed paths:
>     U   php/php-src/branches/PHP_5_2/NEWS
>     U   php/php-src/branches/PHP_5_2/Zend/zend_builtin_functions.c
>     U   php/php-src/branches/PHP_5_3/NEWS
>     U   php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c
>     U   php/php-src/trunk/Zend/zend_builtin_functions.c
> 
> Modified: php/php-src/branches/PHP_5_2/NEWS
> ===================================================================
> --- php/php-src/branches/PHP_5_2/NEWS 2009-12-30 18:41:45 UTC (rev 292822)
> +++ php/php-src/branches/PHP_5_2/NEWS 2009-12-30 19:15:11 UTC (rev 292823)
> @@ -28,6 +28,7 @@
>    then 1024 fields). (Ilia, sjoerd-php at linuxonly dot nl)
>  - Fixed bug #45599 (strip_tags() truncates rest of string with invalid
>    attribute). (Ilia, hradtke)
> +- Fixed bug #44827 (define() allows :: in constant names). (Ilia)
> 
> 
>  17 Dec 2009, PHP 5.2.12
> 
> Modified: php/php-src/branches/PHP_5_2/Zend/zend_builtin_functions.c
> ===================================================================
> --- php/php-src/branches/PHP_5_2/Zend/zend_builtin_functions.c        
> 2009-12-30 18:41:45 UTC (rev 292822)
> +++ php/php-src/branches/PHP_5_2/Zend/zend_builtin_functions.c        
> 2009-12-30 19:15:11 UTC (rev 292823)
> @@ -461,7 +461,6 @@
>       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;
> @@ -472,31 +471,9 @@
>       }
> 
>       /* 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_with_limit((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_with_limit(class_name, use_heap);
> -                     RETURN_FALSE;
> -             }
> -             free_alloca_with_limit(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:
> 
> Modified: php/php-src/branches/PHP_5_3/NEWS
> ===================================================================
> --- php/php-src/branches/PHP_5_3/NEWS 2009-12-30 18:41:45 UTC (rev 292822)
> +++ php/php-src/branches/PHP_5_3/NEWS 2009-12-30 19:15:11 UTC (rev 292823)
> @@ -11,6 +11,7 @@
>    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)
> 
> 
>  ?? ??? 20??, PHP 5.3.2
> 
> Modified: php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c
> ===================================================================
> --- php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c        
> 2009-12-30 18:41:45 UTC (rev 292822)
> +++ php/php-src/branches/PHP_5_3/Zend/zend_builtin_functions.c        
> 2009-12-30 19:15:11 UTC (rev 292823)
> @@ -629,7 +629,6 @@
>       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 @@
>       }
> 
>       /* 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:
> 
> Modified: php/php-src/trunk/Zend/zend_builtin_functions.c
> ===================================================================
> --- php/php-src/trunk/Zend/zend_builtin_functions.c   2009-12-30 18:41:45 UTC 
> (rev 292822)
> +++ php/php-src/trunk/Zend/zend_builtin_functions.c   2009-12-30 19:15:11 UTC 
> (rev 292823)
> @@ -623,12 +623,25 @@
>       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;
>       }
> 
> 
> -- 
> PHP CVS Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to