felipe                                   Sun, 01 Aug 2010 13:27:02 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=301755

Log:
- Fixed bug #52484 (__set() ignores setting properties with empty names)

Bug: http://bugs.php.net/52484 (Open) __set() ignores setting properties with 
empty names
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    A   php/php-src/branches/PHP_5_3/Zend/tests/bug52484.phpt
    A   php/php-src/branches/PHP_5_3/Zend/tests/bug52484_2.phpt
    A   php/php-src/branches/PHP_5_3/Zend/tests/bug52484_3.phpt
    U   php/php-src/branches/PHP_5_3/Zend/zend_object_handlers.c
    A   php/php-src/trunk/Zend/tests/bug52484.phpt
    A   php/php-src/trunk/Zend/tests/bug52484_2.phpt
    A   php/php-src/trunk/Zend/tests/bug52484_3.phpt
    U   php/php-src/trunk/Zend/zend_object_handlers.c

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS	2010-08-01 04:03:08 UTC (rev 301754)
+++ php/php-src/branches/PHP_5_3/NEWS	2010-08-01 13:27:02 UTC (rev 301755)
@@ -2,6 +2,8 @@
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2010, PHP 5.3.4
 - Fixed bug #52487 (PDO::FETCH_INTO leaks memory). (Felipe)
+- Fixed bug #52484 (__set() ignores setting properties with empty names).
+  (Felipe)
 - Fixed bug #52436 (Compile error if systems do not have stdint.h)
   (Sriram Natarajan)


Added: php/php-src/branches/PHP_5_3/Zend/tests/bug52484.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/bug52484.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/Zend/tests/bug52484.phpt	2010-08-01 13:27:02 UTC (rev 301755)
@@ -0,0 +1,19 @@
+--TEST--
+Bug #52484 (__set() ignores setting properties with empty names)
+--FILE--
+<?php
+
+class A {
+	function __unset($prop) {
+		unset($this->$prop);
+	}
+}
+
+$a = new A();
+$prop = null;
+
+unset($a->$prop);
+
+?>
+--EXPECTF--
+Fatal error: Cannot access empty property in %s on line %d


Property changes on: php/php-src/branches/PHP_5_3/Zend/tests/bug52484.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/branches/PHP_5_3/Zend/tests/bug52484_2.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/bug52484_2.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/Zend/tests/bug52484_2.phpt	2010-08-01 13:27:02 UTC (rev 301755)
@@ -0,0 +1,19 @@
+--TEST--
+Bug #52484.2 (__set() ignores setting properties with empty names)
+--FILE--
+<?php
+
+class A {
+	function __set($prop, $val) {
+		$this->$prop = $val;
+	}
+}
+
+$a = new A();
+$prop = null;
+
+$a->$prop = 2;
+
+?>
+--EXPECTF--
+Fatal error: Cannot access empty property in %s on line %d


Property changes on: php/php-src/branches/PHP_5_3/Zend/tests/bug52484_2.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/branches/PHP_5_3/Zend/tests/bug52484_3.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/tests/bug52484_3.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/Zend/tests/bug52484_3.phpt	2010-08-01 13:27:02 UTC (rev 301755)
@@ -0,0 +1,19 @@
+--TEST--
+Bug #52484.3 (__set() ignores setting properties with empty names)
+--FILE--
+<?php
+
+class A {
+	function __get($prop) {
+		var_dump($this->$prop);
+	}
+}
+
+$a = new A();
+$prop = null;
+
+var_dump($a->$prop);
+
+?>
+--EXPECTF--
+Fatal error: Cannot access empty property in %s on line %d


Property changes on: php/php-src/branches/PHP_5_3/Zend/tests/bug52484_3.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/branches/PHP_5_3/Zend/zend_object_handlers.c
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/zend_object_handlers.c	2010-08-01 04:03:08 UTC (rev 301754)
+++ php/php-src/branches/PHP_5_3/Zend/zend_object_handlers.c	2010-08-01 13:27:02 UTC (rev 301755)
@@ -340,7 +340,7 @@
 	property_info = zend_get_property_info(zobj->ce, member, (zobj->ce->__get != NULL) TSRMLS_CC);

 	if (!property_info || zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &retval) == FAILURE) {
-		zend_guard *guard;
+		zend_guard *guard = NULL;

 		if (zobj->ce->__get &&
 		    zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
@@ -373,6 +373,15 @@
 			}
 			zval_ptr_dtor(&object);
 		} else {
+			if (zobj->ce->__get && guard && guard->in_get == 1) {
+				if (Z_STRVAL_P(member)[0] == '\0') {
+					if (Z_STRLEN_P(member) == 0) {
+						zend_error(E_ERROR, "Cannot access empty property");
+					} else {
+						zend_error(E_ERROR, "Cannot access property started with '\\0'");
+					}
+				}
+			}
 			if (!silent) {
 				zend_error(E_NOTICE,"Undefined property: %s::$%s", zobj->ce->name, Z_STRVAL_P(member));
 			}
@@ -437,7 +446,7 @@
 		}
 	} else {
 		int setter_done = 0;
-		zend_guard *guard;
+		zend_guard *guard = NULL;

 		if (zobj->ce->__set &&
 		    zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
@@ -460,6 +469,14 @@
 				SEPARATE_ZVAL(&value);
 			}
 			zend_hash_quick_update(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, &value, sizeof(zval *), (void **) &foo);
+		} else if (zobj->ce->__set && guard && guard->in_set == 1) {
+			if (Z_STRVAL_P(member)[0] == '\0') {
+				if (Z_STRLEN_P(member) == 0) {
+					zend_error(E_ERROR, "Cannot access empty property");
+				} else {
+					zend_error(E_ERROR, "Cannot access property started with '\\0'");
+				}
+			}
 		}
 	}

@@ -619,7 +636,7 @@
 	property_info = zend_get_property_info(zobj->ce, member, (zobj->ce->__unset != NULL) TSRMLS_CC);

 	if (!property_info || zend_hash_quick_del(zobj->properties, property_info->name, property_info->name_length+1, property_info->h) == FAILURE) {
-		zend_guard *guard;
+		zend_guard *guard = NULL;

 		if (zobj->ce->__unset &&
 		    zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
@@ -630,6 +647,14 @@
 			zend_std_call_unsetter(object, member TSRMLS_CC);
 			guard->in_unset = 0;
 			zval_ptr_dtor(&object);
+		} else if (zobj->ce->__unset && guard && guard->in_unset == 1) {
+			if (Z_STRVAL_P(member)[0] == '\0') {
+				if (Z_STRLEN_P(member) == 0) {
+					zend_error(E_ERROR, "Cannot access empty property");
+				} else {
+					zend_error(E_ERROR, "Cannot access property started with '\\0'");
+				}
+			}
 		}
 	}


Added: php/php-src/trunk/Zend/tests/bug52484.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/bug52484.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/bug52484.phpt	2010-08-01 13:27:02 UTC (rev 301755)
@@ -0,0 +1,19 @@
+--TEST--
+Bug #52484 (__set() ignores setting properties with empty names)
+--FILE--
+<?php
+
+class A {
+	function __unset($prop) {
+		unset($this->$prop);
+	}
+}
+
+$a = new A();
+$prop = null;
+
+unset($a->$prop);
+
+?>
+--EXPECTF--
+Fatal error: Cannot access empty property in %s on line %d


Property changes on: php/php-src/trunk/Zend/tests/bug52484.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/trunk/Zend/tests/bug52484_2.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/bug52484_2.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/bug52484_2.phpt	2010-08-01 13:27:02 UTC (rev 301755)
@@ -0,0 +1,19 @@
+--TEST--
+Bug #52484.2 (__set() ignores setting properties with empty names)
+--FILE--
+<?php
+
+class A {
+	function __set($prop, $val) {
+		$this->$prop = $val;
+	}
+}
+
+$a = new A();
+$prop = null;
+
+$a->$prop = 2;
+
+?>
+--EXPECTF--
+Fatal error: Cannot access empty property in %s on line %d


Property changes on: php/php-src/trunk/Zend/tests/bug52484_2.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Added: php/php-src/trunk/Zend/tests/bug52484_3.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/bug52484_3.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/bug52484_3.phpt	2010-08-01 13:27:02 UTC (rev 301755)
@@ -0,0 +1,19 @@
+--TEST--
+Bug #52484.3 (__set() ignores setting properties with empty names)
+--FILE--
+<?php
+
+class A {
+	function __get($prop) {
+		var_dump($this->$prop);
+	}
+}
+
+$a = new A();
+$prop = null;
+
+var_dump($a->$prop);
+
+?>
+--EXPECTF--
+Fatal error: Cannot access empty property in %s on line %d


Property changes on: php/php-src/trunk/Zend/tests/bug52484_3.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/trunk/Zend/zend_object_handlers.c
===================================================================
--- php/php-src/trunk/Zend/zend_object_handlers.c	2010-08-01 04:03:08 UTC (rev 301754)
+++ php/php-src/trunk/Zend/zend_object_handlers.c	2010-08-01 13:27:02 UTC (rev 301755)
@@ -412,7 +412,7 @@
 	            (*(retval = &zobj->properties_table[property_info->offset]) == NULL)) :
 	        (UNEXPECTED(!zobj->properties) ||
 	          UNEXPECTED(zend_hash_quick_find(zobj->properties, property_info->name, property_info->name_length+1, property_info->h, (void **) &retval) == FAILURE)))) {
-		zend_guard *guard;
+		zend_guard *guard = NULL;

 		if (zobj->ce->__get &&
 		    zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
@@ -445,6 +445,15 @@
 			}
 			zval_ptr_dtor(&object);
 		} else {
+			if (zobj->ce->__get && guard && guard->in_get == 1) {
+				if (Z_STRVAL_P(member)[0] == '\0') {
+					if (Z_STRLEN_P(member) == 0) {
+						zend_error(E_ERROR, "Cannot access empty property");
+					} else {
+						zend_error(E_ERROR, "Cannot access property started with '\\0'");
+					}
+				}
+			}
 			if (!silent) {
 				zend_error(E_NOTICE,"Undefined property: %s::$%s", zobj->ce->name, Z_STRVAL_P(member));
 			}
@@ -517,7 +526,7 @@
 		}
 	} else {
 		int setter_done = 0;
-		zend_guard *guard;
+		zend_guard *guard = NULL;

 		if (zobj->ce->__set &&
 		    zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
@@ -530,6 +539,14 @@
 			setter_done = 1;
 			guard->in_set = 0;
 			zval_ptr_dtor(&object);
+		} else if (zobj->ce->__set && guard && guard->in_set == 1) {
+			if (Z_STRVAL_P(member)[0] == '\0') {
+				if (Z_STRLEN_P(member) == 0) {
+					zend_error(E_ERROR, "Cannot access empty property");
+				} else {
+					zend_error(E_ERROR, "Cannot access property started with '\\0'");
+				}
+			}
 		}
 		if (!setter_done && EXPECTED(property_info != NULL)) {
 			/* if we assign referenced variable, we should separate it */
@@ -746,7 +763,7 @@
 	} else if (UNEXPECTED(!property_info) ||
 	           !zobj->properties ||
 	           UNEXPECTED(zend_hash_quick_del(zobj->properties, property_info->name, property_info->name_length+1, property_info->h) == FAILURE)) {
-		zend_guard *guard;
+		zend_guard *guard = NULL;

 		if (zobj->ce->__unset &&
 		    zend_get_property_guard(zobj, property_info, member, &guard) == SUCCESS &&
@@ -757,6 +774,14 @@
 			zend_std_call_unsetter(object, member TSRMLS_CC);
 			guard->in_unset = 0;
 			zval_ptr_dtor(&object);
+		} else if (zobj->ce->__unset && guard && guard->in_unset == 1) {
+			if (Z_STRVAL_P(member)[0] == '\0') {
+				if (Z_STRLEN_P(member) == 0) {
+					zend_error(E_ERROR, "Cannot access empty property");
+				} else {
+					zend_error(E_ERROR, "Cannot access property started with '\\0'");
+				}
+			}
 		}
 	} else if (EXPECTED(property_info != NULL) &&
 	           EXPECTED((property_info->flags & ZEND_ACC_STATIC) == 0) &&
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to