[PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/zend_compile.c branches/PHP_5_4/Zend/zend_object_handlers.c trunk/Zend/zend_compile.c trunk/Zend/zend_object_handlers.c

2011-12-19 Thread Xinchen Hui
laruence Mon, 19 Dec 2011 16:48:18 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=321166

Log:
Fixed bug #60558 (Invalid read and writes)
Re-Fixed bug #60536 (Traits Segfault)
#Thanks to tony2001, I found the previous fix -r321089 is actually not a 
correct one.
#The key problem there is because the traits didn't correct set the 
property_info.offset
#for private properties. so here come the new fix.

Bugs: https://bugs.php.net/60558 (Re-Opened) Invalid read and writes
  https://bugs.php.net/60536 (Closed) Traits Segfault
  
Changed paths:
U   php/php-src/branches/PHP_5_4/NEWS
U   php/php-src/branches/PHP_5_4/Zend/zend_compile.c
U   php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c
U   php/php-src/trunk/Zend/zend_compile.c
U   php/php-src/trunk/Zend/zend_object_handlers.c

Modified: php/php-src/branches/PHP_5_4/NEWS
===
--- php/php-src/branches/PHP_5_4/NEWS	2011-12-19 16:14:50 UTC (rev 321165)
+++ php/php-src/branches/PHP_5_4/NEWS	2011-12-19 16:48:18 UTC (rev 321166)
@@ -7,6 +7,7 @@
   . Fixed bug #60536 (Traits Segfault). (Laruence)
   . Fixed bug #60362 (non-existent sub-sub keys should not have values).
 (Laruence, alan_k, Stas)
+  . Fixed bug #60558 (Invalid read and writes). (Laruence)

 - CLI SAPI:
   . Fixed bug #60477 (Segfault after two multipart/form-data POST requests,

Modified: php/php-src/branches/PHP_5_4/Zend/zend_compile.c
===
--- php/php-src/branches/PHP_5_4/Zend/zend_compile.c	2011-12-19 16:14:50 UTC (rev 321165)
+++ php/php-src/branches/PHP_5_4/Zend/zend_compile.c	2011-12-19 16:48:18 UTC (rev 321166)
@@ -4208,6 +4208,50 @@
 }
 /* }}} */

+static void zend_traits_register_private_property(zend_class_entry *ce, const char *name, int name_len, zend_property_info *old_info, zval *property TSRMLS_DC) /* {{{ */
+{
+	char *priv_name;
+	int priv_name_length;
+	const char *interned_name;
+	zend_property_info property_info;
+	ulong h = zend_get_hash_value(name, name_len+1);
+	property_info = *old_info;
+
+	if (old_info-flags  ZEND_ACC_STATIC) {
+		property_info.offset = ce-default_static_members_count++;
+		ce-default_static_members_table = perealloc(ce-default_static_members_table, sizeof(zval*) * ce-default_static_members_count, ce-type == ZEND_INTERNAL_CLASS);
+		ce-default_static_members_table[property_info.offset] = property;
+		if (ce-type == ZEND_USER_CLASS) {
+			ce-static_members_table = ce-default_static_members_table;
+		}
+	} else {
+		property_info.offset = ce-default_properties_count++;
+		ce-default_properties_table = perealloc(ce-default_properties_table, sizeof(zval*) * ce-default_properties_count, ce-type == ZEND_INTERNAL_CLASS);
+		ce-default_properties_table[property_info.offset] = property;
+	}
+
+	zend_mangle_property_name(priv_name, priv_name_length, ce-name, ce-name_length, name, name_len, ce-type  ZEND_INTERNAL_CLASS);
+	property_info.name = priv_name;
+	property_info.name_length = priv_name_length;
+
+	interned_name = zend_new_interned_string(property_info.name, property_info.name_length+1, 0 TSRMLS_CC);
+	if (interned_name != property_info.name) {
+		if (ce-type == ZEND_USER_CLASS) {
+			efree((char*)property_info.name);
+		} else {
+			free((char*)property_info.name);
+		}
+		property_info.name = interned_name;
+	}
+
+	property_info.h = zend_get_hash_value(property_info.name, property_info.name_length+1);
+
+	property_info.ce = ce;
+
+	zend_hash_quick_update(ce-properties_info, name, name_len+1, h, property_info, sizeof(zend_property_info), NULL);
+}
+/* }}} */
+
 static void zend_do_traits_property_binding(zend_class_entry *ce TSRMLS_DC) /* {{{ */
 {
 	size_t i;
@@ -4295,6 +4339,17 @@
 	prop_name,
 	ce-name);
 	}
+} else {
+	/* private property, make the property_info.offset indenpended */
+	if (property_info-flags  ZEND_ACC_STATIC) {
+		prop_value = ce-traits[i]-default_static_members_table[property_info-offset];
+	} else {
+		prop_value = ce-traits[i]-default_properties_table[property_info-offset];
+	}
+	Z_ADDREF_P(prop_value);
+
+	zend_traits_register_private_property(ce, prop_name, prop_name_length, property_info, prop_value TSRMLS_CC);
+	return;
 }
 			}


Modified: php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c
===
--- php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c	2011-12-19 16:14:50 UTC (rev 321165)
+++ php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c	2011-12-19 16:48:18 UTC (rev 321166)
@@ -62,7 +62,6 @@
 		ALLOC_HASHTABLE(zobj-properties);
 		zend_hash_init(zobj-properties, 0, NULL, ZVAL_PTR_DTOR, 0);
 		if (ce-default_properties_count) {
-			char *flags = ecalloc(ce-default_properties_count, sizeof(char));
 			for (zend_hash_internal_pointer_reset_ex(ce-properties_info, pos);
 			 

Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/zend_compile.c branches/PHP_5_4/Zend/zend_object_handlers.c trunk/Zend/zend_compile.c trunk/Zend/zend_object_handlers.c

2011-12-19 Thread Stefan Marr
Hi:

Thanks guys!

I have only briefly rechecked the code, and dont remember at the moment how the 
default property table works, but for me it feels like these offsets are also 
incorrect for public or protected stuff that gets newly added to the class?

Best regards
Stefan

On 19 Dec 2011, at 17:48, Xinchen Hui wrote:

 laruence Mon, 19 Dec 2011 16:48:18 +
 
 Revision: http://svn.php.net/viewvc?view=revisionrevision=321166
 
 Log:
 Fixed bug #60558 (Invalid read and writes)
 Re-Fixed bug #60536 (Traits Segfault)
 #Thanks to tony2001, I found the previous fix -r321089 is actually not a 
 correct one.
 #The key problem there is because the traits didn't correct set the 
 property_info.offset
 #for private properties. so here come the new fix.
 
 Bugs: https://bugs.php.net/60558 (Re-Opened) Invalid read and writes
  https://bugs.php.net/60536 (Closed) Traits Segfault
 
 Changed paths:
U   php/php-src/branches/PHP_5_4/NEWS
U   php/php-src/branches/PHP_5_4/Zend/zend_compile.c
U   php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c
U   php/php-src/trunk/Zend/zend_compile.c
U   php/php-src/trunk/Zend/zend_object_handlers.c
 
 svn-diffs-321166.txt-- 
 PHP CVS Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax:   +32 2 629 3525


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/zend_compile.c branches/PHP_5_4/Zend/zend_object_handlers.c trunk/Zend/zend_compile.c trunk/Zend/zend_object_handlers.c

2011-12-19 Thread Xinchen Hui
Hi:
 For public and protected properties, you will have only one copy
in the child class, so there is no such conflict.

Thanks

Sent from my iPhone

在 2011-12-20,1:12,Stefan Marr p...@stefan-marr.de 写道:

 Hi:

 Thanks guys!

 I have only briefly rechecked the code, and dont remember at the moment how 
 the default property table works, but for me it feels like these offsets are 
 also incorrect for public or protected stuff that gets newly added to the 
 class?

 Best regards
 Stefan

 On 19 Dec 2011, at 17:48, Xinchen Hui wrote:

 laruence Mon, 19 Dec 2011 16:48:18 +

 Revision: http://svn.php.net/viewvc?view=revisionrevision=321166

 Log:
 Fixed bug #60558 (Invalid read and writes)
 Re-Fixed bug #60536 (Traits Segfault)
 #Thanks to tony2001, I found the previous fix -r321089 is actually not a 
 correct one.
 #The key problem there is because the traits didn't correct set the 
 property_info.offset
 #for private properties. so here come the new fix.

 Bugs: https://bugs.php.net/60558 (Re-Opened) Invalid read and writes
 https://bugs.php.net/60536 (Closed) Traits Segfault

 Changed paths:
   U   php/php-src/branches/PHP_5_4/NEWS
   U   php/php-src/branches/PHP_5_4/Zend/zend_compile.c
   U   php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c
   U   php/php-src/trunk/Zend/zend_compile.c
   U   php/php-src/trunk/Zend/zend_object_handlers.c

 svn-diffs-321166.txt--
 PHP CVS Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 --
 Stefan Marr
 Software Languages Lab
 Vrije Universiteit Brussel
 Pleinlaan 2 / B-1050 Brussels / Belgium
 http://soft.vub.ac.be/~smarr
 Phone: +32 2 629 2974
 Fax:   +32 2 629 3525


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] svn: /php/php-src/ branches/PHP_5_4/NEWS branches/PHP_5_4/Zend/zend_compile.c branches/PHP_5_4/Zend/zend_object_handlers.c trunk/Zend/zend_compile.c trunk/Zend/zend_object_handlers.c

2011-12-19 Thread Xinchen Hui
s/class/object/

Sent from my iPhone

在 2011-12-20,9:29,Xinchen Hui larue...@gmail.com 写道:

 Hi:
 For public and protected properties, you will have only one copy
 in the child class, so there is no such conflict.

 Thanks

 Sent from my iPhone

 在 2011-12-20,1:12,Stefan Marr p...@stefan-marr.de 写道:

 Hi:

 Thanks guys!

 I have only briefly rechecked the code, and dont remember at the moment how 
 the default property table works, but for me it feels like these offsets are 
 also incorrect for public or protected stuff that gets newly added to the 
 class?

 Best regards
 Stefan

 On 19 Dec 2011, at 17:48, Xinchen Hui wrote:

 laruence Mon, 19 Dec 2011 16:48:18 +

 Revision: http://svn.php.net/viewvc?view=revisionrevision=321166

 Log:
 Fixed bug #60558 (Invalid read and writes)
 Re-Fixed bug #60536 (Traits Segfault)
 #Thanks to tony2001, I found the previous fix -r321089 is actually not a 
 correct one.
 #The key problem there is because the traits didn't correct set the 
 property_info.offset
 #for private properties. so here come the new fix.

 Bugs: https://bugs.php.net/60558 (Re-Opened) Invalid read and writes
https://bugs.php.net/60536 (Closed) Traits Segfault

 Changed paths:
  U   php/php-src/branches/PHP_5_4/NEWS
  U   php/php-src/branches/PHP_5_4/Zend/zend_compile.c
  U   php/php-src/branches/PHP_5_4/Zend/zend_object_handlers.c
  U   php/php-src/trunk/Zend/zend_compile.c
  U   php/php-src/trunk/Zend/zend_object_handlers.c

 svn-diffs-321166.txt--
 PHP CVS Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

 --
 Stefan Marr
 Software Languages Lab
 Vrije Universiteit Brussel
 Pleinlaan 2 / B-1050 Brussels / Belgium
 http://soft.vub.ac.be/~smarr
 Phone: +32 2 629 2974
 Fax:   +32 2 629 3525


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php