com php-src: Allow empty property names: Zend/tests/bug29015.phpt Zend/tests/bug52484.phpt Zend/tests/bug52484_2. phpt Zend/tests/bug52484_3.phpt
Zend/zend _object_handlers.c
| From: | Nikita Popov | Date: | Tue, 24 May 2016 16:34:17 +0000 |
| Subject: | com php-src: Allow empty property names: Zend/tests/bug29015.phpt Zend/tests/bug52484.phpt Zend/tests/bug52484_2. phpt Zend/tests/bug52484_3.phpt Zend/zend _object_handlers.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92185@lists.php.net to get a copy of this message | ||
Commit: 674297c7e41013c2c34d770051714518d0586271
Author: Nikita Popov <nikic@php.net> Wed, 23 Mar 2016 18:57:59 +0100
Parents: a19eb8e34abc0b41e821cbf67930bf64fcb9e65d
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=674297c7e41013c2c34d770051714518d0586271
Log:
Allow empty property names
Conflicts:
Zend/zend_compile.c
Changed paths:
M Zend/tests/bug29015.phpt
M Zend/tests/bug52484.phpt
M Zend/tests/bug52484_2.phpt
M Zend/tests/bug52484_3.phpt
M Zend/zend_object_handlers.c
Diff:
diff --git a/Zend/tests/bug29015.phpt b/Zend/tests/bug29015.phpt
index a36ed92..d4231d1 100644
--- a/Zend/tests/bug29015.phpt
+++ b/Zend/tests/bug29015.phpt
@@ -6,9 +6,16 @@ $a = new stdClass();
$x = "";
$a->$x = "string('')";
var_dump($a);
+$a->{"\0"} = 42;
+var_dump($a);
?>
--EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %sbug29015.php:4
+object(stdClass)#1 (1) {
+ [""]=>
+ string(10) "string('')"
+}
+
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
Stack trace:
#0 {main}
- thrown in %sbug29015.php on line 4
+ thrown in %s on line %d
diff --git a/Zend/tests/bug52484.phpt b/Zend/tests/bug52484.phpt
index 0535296..1d2c2d7 100644
--- a/Zend/tests/bug52484.phpt
+++ b/Zend/tests/bug52484.phpt
@@ -10,14 +10,14 @@ class A {
}
$a = new A();
-$prop = null;
+$prop = "\0";
unset($a->$prop);
?>
--EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %s:%d
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
Stack trace:
-#0 %s(%d): A->__unset('')
+#0 %s(%d): A->__unset('\x00')
#1 {main}
thrown in %s on line %d
diff --git a/Zend/tests/bug52484_2.phpt b/Zend/tests/bug52484_2.phpt
index 6bb9275..3b12950 100644
--- a/Zend/tests/bug52484_2.phpt
+++ b/Zend/tests/bug52484_2.phpt
@@ -10,14 +10,14 @@ class A {
}
$a = new A();
-$prop = null;
+$prop = "\0";
$a->$prop = 2;
?>
--EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %s:%d
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
Stack trace:
-#0 %s(%d): A->__set('', 2)
+#0 %s(%d): A->__set('\x00', 2)
#1 {main}
thrown in %s on line %d
diff --git a/Zend/tests/bug52484_3.phpt b/Zend/tests/bug52484_3.phpt
index af32bc9..408dd45 100644
--- a/Zend/tests/bug52484_3.phpt
+++ b/Zend/tests/bug52484_3.phpt
@@ -10,14 +10,14 @@ class A {
}
$a = new A();
-$prop = null;
+$prop = "\0";
var_dump($a->$prop);
?>
--EXPECTF--
-Fatal error: Uncaught Error: Cannot access empty property in %s:%d
+Fatal error: Uncaught Error: Cannot access property started with '\0' in %s:%d
Stack trace:
-#0 %s(%d): A->__get('')
+#0 %s(%d): A->__get('\x00')
#1 {main}
thrown in %s on line %d
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index 6aa5d73..d95f5d9 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -339,13 +339,9 @@ static zend_always_inline uint32_t zend_get_property_offset(zend_class_entry
*ce
return (uint32_t)(intptr_t)CACHED_PTR_EX(cache_slot + 1);
}
- if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0')) {
+ if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0' && ZSTR_LEN(member) != 0)) {
if (!silent) {
- if (ZSTR_LEN(member) == 0) {
- zend_throw_error(NULL, "Cannot access empty property");
- } else {
- zend_throw_error(NULL, "Cannot access property started with '\\0'");
- }
+ zend_throw_error(NULL, "Cannot access property started with '\\0'");
}
return ZEND_WRONG_PROPERTY_OFFSET;
}
@@ -424,13 +420,9 @@ ZEND_API zend_property_info *zend_get_property_info(zend_class_entry *ce,
zend_s
uint32_t flags;
zend_class_entry *scope;
- if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0')) {
+ if (UNEXPECTED(ZSTR_VAL(member)[0] == '\0' && ZSTR_LEN(member) != 0)) {
if (!silent) {
- if (ZSTR_LEN(member) == 0) {
- zend_throw_error(NULL, "Cannot access empty property");
- } else {
- zend_throw_error(NULL, "Cannot access property started with '\\0'");
- }
+ zend_throw_error(NULL, "Cannot access property started with '\\0'");
}
return ZEND_WRONG_PROPERTY_INFO;
}
@@ -679,16 +671,10 @@ zval *zend_std_read_property(zval *object, zval *member, int type, void
**cache_
zval_ptr_dtor(&tmp_object);
goto exit;
} else {
- if (Z_STRVAL_P(member)[0] == '\0') {
- if (Z_STRLEN_P(member) == 0) {
- zend_throw_error(NULL, "Cannot access empty property");
- retval = &EG(uninitialized_zval);
- goto exit;
- } else {
- zend_throw_error(NULL, "Cannot access property started with '\\0'");
- retval = &EG(uninitialized_zval);
- goto exit;
- }
+ if (Z_STRVAL_P(member)[0] == '\0' && Z_STRLEN_P(member) != 0) {
+ zend_throw_error(NULL, "Cannot access property started with '\\0'");
+ retval = &EG(uninitialized_zval);
+ goto exit;
}
}
}
@@ -764,14 +750,9 @@ found:
} else if (EXPECTED(property_offset != ZEND_WRONG_PROPERTY_OFFSET)) {
goto write_std_property;
} else {
- if (Z_STRVAL_P(member)[0] == '\0') {
- if (Z_STRLEN_P(member) == 0) {
- zend_throw_error(NULL, "Cannot access empty property");
- goto exit;
- } else {
- zend_throw_error(NULL, "Cannot access property started with '\\0'");
- goto exit;
- }
+ if (Z_STRVAL_P(member)[0] == '\0' && Z_STRLEN_P(member) != 0) {
+ zend_throw_error(NULL, "Cannot access property started with '\\0'");
+ goto exit;
}
}
} else if (EXPECTED(property_offset != ZEND_WRONG_PROPERTY_OFFSET)) {
@@ -1030,14 +1011,9 @@ static void zend_std_unset_property(zval *object, zval *member, void
**cache_slo
(*guard) &= ~IN_UNSET;
zval_ptr_dtor(&tmp_object);
} else {
- if (Z_STRVAL_P(member)[0] == '\0') {
- if (Z_STRLEN_P(member) == 0) {
- zend_throw_error(NULL, "Cannot access empty property");
- goto exit;
- } else {
- zend_throw_error(NULL, "Cannot access property started with '\\0'");
- goto exit;
- }
+ if (Z_STRVAL_P(member)[0] == '\0' && Z_STRLEN_P(member) != 0) {
+ zend_throw_error(NULL, "Cannot access property started with '\\0'");
+ goto exit;
}
}
}