Skip to content

Commit

Permalink
merge r292823 Fixed bug #44827 (define() allows :: in constant names)…
Browse files Browse the repository at this point in the history
…. (iliaa)

and r293974 Added test case for bug #44827 (iliaa)
  • Loading branch information
johannes committed Jan 25, 2010
1 parent 927580e commit f61ee70
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Zend/tests/bug44827.phpt
@@ -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
29 changes: 3 additions & 26 deletions Zend/zend_builtin_functions.c
Expand Up @@ -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;
Expand All @@ -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:
Expand Down

0 comments on commit f61ee70

Please sign in to comment.