]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #47549 (get_defined_constants() return array with broken
authorIlia Alshanetsky <iliaa@php.net>
Tue, 3 Mar 2009 23:43:06 +0000 (23:43 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 3 Mar 2009 23:43:06 +0000 (23:43 +0000)
array categories)

Zend/zend_builtin_functions.c

index f976c7500b30376c94ff5798e35fdc8920097208..354fc9c6c88e5845ba8aa4b9cee125f7e68b2867 100644 (file)
@@ -25,6 +25,7 @@
 #include "zend_constants.h"
 #include "zend_ini.h"
 #include "zend_extensions.h"
+#include <ctype.h>
 
 #undef ZEND_TEST_EXCEPTIONS
 
@@ -626,6 +627,40 @@ ZEND_FUNCTION(define)
                return;
        }
 
+       /* check if class constant */
+       if ((p = memchr(name, ':', name_len))) {
+               char *s = name;
+               zend_class_entry **ce;
+
+               if (*(p + 1) != ':') { /* invalid constant specifier */
+                       RETURN_FALSE;
+               } else if ((p + 2) >= (name + name_len)) { /* constant name length < 1 */
+                       zend_error(E_WARNING, "Constants name cannot be empty");
+                       RETURN_FALSE;
+               } else if (zend_lookup_class(s, (p - s), &ce TSRMLS_CC) != SUCCESS) { /* invalid class name */
+                       zend_error(E_WARNING, "Class does not exists");
+                       RETURN_FALSE;
+               } else { /* check of constant name contains invalid chars */
+                       int ok = 1;
+                       p += 2; /* move beyond :: to 1st char of constant's name */
+
+                       if (!isalpha(*p) && *p != '_') {
+                               ok = 0;
+                       }
+
+                       while (ok && *++p) {
+                               if (!isalnum(*p) && *p != '_') {
+                                       ok = 0;
+                                       break;
+                               }
+                       }
+
+                       if (!ok) {
+                               RETURN_FALSE;
+                       }
+               }
+       }
+
        if(non_cs) {
                case_sensitive = 0;
        }
@@ -1885,7 +1920,8 @@ ZEND_FUNCTION(get_defined_constants)
                module_names[0] = "internal";
                zend_hash_internal_pointer_reset_ex(&module_registry, &pos);
                while (zend_hash_get_current_data_ex(&module_registry, (void *) &module, &pos) != FAILURE) {
-                       module_names[i++] = (char*)module->name;
+                       module_names[module->module_number] = (char *)module->name;
+                       i++;
                        zend_hash_move_forward_ex(&module_registry, &pos);
                }
                module_names[i] = "user";