From a90a0305b097f4a8f3d578077f020bb6f2ffda9a Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 12 Nov 2007 15:52:22 +0000 Subject: [PATCH] Fixed bug #43183 ("use" of the same class in difference scripts results in a fatal error) --- Zend/tests/bug43183.phpt | 12 ++++++++++++ Zend/zend_compile.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100755 Zend/tests/bug43183.phpt diff --git a/Zend/tests/bug43183.phpt b/Zend/tests/bug43183.phpt new file mode 100755 index 0000000000..61313eb2c6 --- /dev/null +++ b/Zend/tests/bug43183.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #43183 ("use" of the same class in difference scripts results in a fatal error) +--FILE-- +u.constant)+1)) { - zend_error(E_COMPILE_ERROR, "Class name '%s' conflicts with import name", Z_STRVAL(class_name->u.constant)); + zend_hash_find(CG(current_import), lcname, Z_STRLEN(class_name->u.constant)+1, (void**)&ns_name) == SUCCESS) { + error = 1; } if (CG(current_namespace)) { @@ -3012,6 +3014,16 @@ void zend_do_begin_class_declaration(znode *class_token, znode *class_name, znod lcname = zend_str_tolower_dup(Z_STRVAL(class_name->u.constant), Z_STRLEN(class_name->u.constant)); } + if (error) { + char *tmp = zend_str_tolower_dup(Z_STRVAL_PP(ns_name), Z_STRLEN_PP(ns_name)); + + if (Z_STRLEN_PP(ns_name) != Z_STRLEN(class_name->u.constant) || + memcmp(tmp, lcname, Z_STRLEN(class_name->u.constant))) { + zend_error(E_COMPILE_ERROR, "Class name '%s' conflicts with import name", Z_STRVAL(class_name->u.constant)); + } + efree(tmp); + } + new_class_entry = emalloc(sizeof(zend_class_entry)); new_class_entry->type = ZEND_USER_CLASS; new_class_entry->name = class_name->u.constant.value.str.val; @@ -4660,11 +4672,23 @@ void zend_do_use(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */ ns_name[Z_STRLEN_P(CG(current_namespace))+1] = ':'; memcpy(ns_name+Z_STRLEN_P(CG(current_namespace))+2, lcname, Z_STRLEN_P(name)+1); if (zend_hash_exists(CG(class_table), ns_name, Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name)+1)) { - zend_error(E_COMPILE_ERROR, "Import name '%s' conflicts with defined class", Z_STRVAL_P(name)); + char *tmp = zend_str_tolower_dup(Z_STRVAL_P(ns), Z_STRLEN_P(ns)); + + if (Z_STRLEN_P(ns) != Z_STRLEN_P(CG(current_namespace)) + 2 + Z_STRLEN_P(name) || + memcmp(tmp, ns_name, Z_STRLEN_P(ns))) { + zend_error(E_COMPILE_ERROR, "Import name '%s' conflicts with defined class", Z_STRVAL_P(name)); + } + efree(tmp); } efree(ns_name); } else if (zend_hash_exists(CG(class_table), lcname, Z_STRLEN_P(name)+1)) { - zend_error(E_COMPILE_ERROR, "Import name '%s' conflicts with defined class", Z_STRVAL_P(name)); + char *tmp = zend_str_tolower_dup(Z_STRVAL_P(ns), Z_STRLEN_P(ns)); + + if (Z_STRLEN_P(ns) != Z_STRLEN_P(name) || + memcmp(tmp, lcname, Z_STRLEN_P(ns))) { + zend_error(E_COMPILE_ERROR, "Import name '%s' conflicts with defined class", Z_STRVAL_P(name)); + } + efree(tmp); } if (zend_hash_add(CG(current_import), lcname, Z_STRLEN_P(name)+1, &ns, sizeof(zval*), NULL) != SUCCESS) { -- 2.50.1