cvs: ZendEngine2(PHP_5_3) / zend_compile.c /tests bug43183.phpt
| From: | Dmitry Stogov | Date: | Mon, 12 Nov 2007 15:52:22 +0000 |
| Subject: | cvs: ZendEngine2(PHP_5_3) / zend_compile.c /tests bug43183.phpt | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-6155@lists.php.net to get a copy of this message | ||
dmitry Mon Nov 12 15:52:22 2007 UTC
Added files: (Branch: PHP_5_3)
/ZendEngine2/tests bug43183.phpt
Modified files:
/ZendEngine2 zend_compile.c
Log:
Fixed bug #43183 ("use" of the same class in difference scripts results in a fatal
error)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.647.2.27.2.41.2.17&r2=1.647.2.27.2.41.2.18&diff_format=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.17
ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.18
--- ZendEngine2/zend_compile.c:1.647.2.27.2.41.2.17 Fri Nov 9 13:34:39 2007
+++ ZendEngine2/zend_compile.c Mon Nov 12 15:52:22 2007
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.17 2007/11/09 13:34:39 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.647.2.27.2.41.2.18 2007/11/12 15:52:22 dmitry Exp $ */
#include <zend_language_parser.h>
#include "zend.h"
@@ -2981,6 +2981,8 @@
int doing_inheritance = 0;
zend_class_entry *new_class_entry;
char *lcname;
+ int error = 0;
+ zval **ns_name;
if (CG(active_class_entry)) {
zend_error(E_COMPILE_ERROR, "Class declarations may not be nested");
@@ -2996,8 +2998,8 @@
/* Class name must not conflict with import names */
if (CG(current_import) &&
- zend_hash_exists(CG(current_import), lcname, Z_STRLEN(class_name->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 @@
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 @@
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) {
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/bug43183.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/bug43183.phpt
+++ ZendEngine2/tests/bug43183.phpt
--TEST--
Bug #43183 ("use" of the same class in difference scripts results in a fatal error)
--FILE--
<?php
namespace Test;
use Test::Foo;
class Foo {}
class Bar {}
use Test::Bar;
echo "ok\n";
--EXPECT--
ok