From a706d6baa4e5a7bea9b4e1346fc3134ec0b1b66e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Thu, 18 Aug 2022 13:48:20 +0200 Subject: [PATCH] Fix tests and review suggestions --- Zend/zend_API.c | 38 ++++--------------- Zend/zend_API.h | 2 - Zend/zend_object_handlers.c | 22 +++++++++++ ext/gmp/tests/serialize.phpt | 2 + ext/session/tests/003.phpt | 1 + ext/session/tests/004.phpt | 1 + ext/session/tests/005.phpt | 1 + ext/session/tests/023.phpt | 1 + ext/session/tests/024.phpt | 1 + ext/session/tests/025.phpt | 1 + ext/soap/tests/bug70388.phpt | 2 + ext/soap/tests/bugs/bug69085.phpt | 1 + ext/standard/tests/serialize/bug49649.phpt | 4 +- ext/standard/tests/serialize/bug49649_1.phpt | 2 +- ext/standard/tests/serialize/bug49649_2.phpt | 2 +- ...ialize_overwrite_undeclared_protected.phpt | 2 +- ...lize_ref_to_overwritten_declared_prop.phpt | 4 +- ext/standard/var_unserializer.re | 8 ++-- 18 files changed, 52 insertions(+), 43 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 055a62b333879..9f6f8018d96b0 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1586,28 +1586,6 @@ ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properti } /* }}} */ -ZEND_API zend_never_inline void zend_forbidden_dynamic_property(zend_class_entry *ce, zend_string *member) { - zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", - ZSTR_VAL(ce->name), ZSTR_VAL(member)); -} - -ZEND_API zend_never_inline bool zend_deprecated_dynamic_property(zend_object *obj, zend_string *member) { - GC_ADDREF(obj); - zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated", - ZSTR_VAL(obj->ce->name), ZSTR_VAL(member)); - if (UNEXPECTED(GC_DELREF(obj) == 0)) { - zend_class_entry *ce = obj->ce; - zend_objects_store_del(obj); - if (!EG(exception)) { - /* We cannot continue execution and have to throw an exception */ - zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", - ZSTR_VAL(ce->name), ZSTR_VAL(member)); - } - return 0; - } - return 1; -} - ZEND_API void object_properties_load(zend_object *object, HashTable *properties) /* {{{ */ { zval *prop, tmp; @@ -1650,12 +1628,12 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties) } } else { if (UNEXPECTED(object->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) { - zend_forbidden_dynamic_property(object->ce, key); + zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", + ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key)); return; } else if (!(object->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) { - if (!zend_deprecated_dynamic_property(object, key)) { - return; - } + zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated", + ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key)); } if (!object->properties) { @@ -1666,12 +1644,12 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties) } } else { if (UNEXPECTED(object->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) { - zend_forbidden_dynamic_property(object->ce, key); + zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", + ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key)); return; } else if (!(object->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) { - if (!zend_deprecated_dynamic_property(object, key)) { - return; - } + zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated", + ZSTR_VAL(object->ce->name), zend_get_unmangled_property_name(key)); } if (!object->properties) { diff --git a/Zend/zend_API.h b/Zend/zend_API.h index af7cfba12fffc..2970299836689 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -522,8 +522,6 @@ ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce); ZEND_API zend_result object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties); ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type); ZEND_API void object_properties_init_ex(zend_object *object, HashTable *properties); -ZEND_API zend_never_inline void zend_forbidden_dynamic_property(zend_class_entry *ce, zend_string *member); -ZEND_API zend_never_inline bool zend_deprecated_dynamic_property(zend_object *obj, zend_string *member); ZEND_API void object_properties_load(zend_object *object, HashTable *properties); ZEND_API void zend_merge_properties(zval *obj, HashTable *properties); diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index a11b5578bb57d..1a76f35d6689e 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -275,6 +275,28 @@ static ZEND_COLD zend_never_inline void zend_bad_property_name(void) /* {{{ */ } /* }}} */ +ZEND_API zend_never_inline void zend_forbidden_dynamic_property(zend_class_entry *ce, zend_string *member) { + zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", + ZSTR_VAL(ce->name), ZSTR_VAL(member)); +} + +ZEND_API zend_never_inline bool zend_deprecated_dynamic_property(zend_object *obj, zend_string *member) { + GC_ADDREF(obj); + zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated", + ZSTR_VAL(obj->ce->name), ZSTR_VAL(member)); + if (UNEXPECTED(GC_DELREF(obj) == 0)) { + zend_class_entry *ce = obj->ce; + zend_objects_store_del(obj); + if (!EG(exception)) { + /* We cannot continue execution and have to throw an exception */ + zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", + ZSTR_VAL(ce->name), ZSTR_VAL(member)); + } + return 0; + } + return 1; +} + static ZEND_COLD zend_never_inline void zend_readonly_property_modification_scope_error( zend_class_entry *ce, zend_string *member, zend_class_entry *scope, const char *operation) { zend_throw_error(NULL, "Cannot %s readonly property %s::$%s from %s%s", diff --git a/ext/gmp/tests/serialize.phpt b/ext/gmp/tests/serialize.phpt index 65c2f34e13d17..84877459a9bc0 100644 --- a/ext/gmp/tests/serialize.phpt +++ b/ext/gmp/tests/serialize.phpt @@ -54,6 +54,8 @@ object(GMP)#%d (1) { Deprecated: Creation of dynamic property GMP::$foo is deprecated in %s on line %d string(56) "O:3:"GMP":2:{i:0;s:1:"d";i:1;a:1:{s:3:"foo";s:3:"bar";}}" + +Deprecated: Creation of dynamic property GMP::$foo is deprecated in %s on line %d object(GMP)#%d (2) { ["foo"]=> string(3) "bar" diff --git a/ext/session/tests/003.phpt b/ext/session/tests/003.phpt index c0628e28abdd9..ab1739edf6b76 100644 --- a/ext/session/tests/003.phpt +++ b/ext/session/tests/003.phpt @@ -16,6 +16,7 @@ error_reporting(E_ALL); class foo { public $bar = "ok"; + public $yes; function method() { $this->yes++; } } diff --git a/ext/session/tests/004.phpt b/ext/session/tests/004.phpt index 0901286001808..d6b53072c1633 100644 --- a/ext/session/tests/004.phpt +++ b/ext/session/tests/004.phpt @@ -52,6 +52,7 @@ $hnd = new handler; class foo { public $bar = "ok"; + public $yes; function method() { $this->yes++; } } diff --git a/ext/session/tests/005.phpt b/ext/session/tests/005.phpt index 6c7f246a3630a..c4083557866e3 100644 --- a/ext/session/tests/005.phpt +++ b/ext/session/tests/005.phpt @@ -53,6 +53,7 @@ $hnd = new handler; class foo { public $bar = "ok"; + public $yes; function method() { $this->yes++; } } diff --git a/ext/session/tests/023.phpt b/ext/session/tests/023.phpt index 78f6e41c7e790..092f8db64b790 100644 --- a/ext/session/tests/023.phpt +++ b/ext/session/tests/023.phpt @@ -16,6 +16,7 @@ error_reporting(E_ALL); class foo { public $bar = "ok"; + public $yes; function method() { $this->yes++; } } diff --git a/ext/session/tests/024.phpt b/ext/session/tests/024.phpt index b0f819b9d0d2f..c307d79a6873b 100644 --- a/ext/session/tests/024.phpt +++ b/ext/session/tests/024.phpt @@ -53,6 +53,7 @@ $hnd = new handler; class foo { public $bar = "ok"; + public $yes; function method() { $this->yes++; } } diff --git a/ext/session/tests/025.phpt b/ext/session/tests/025.phpt index b18715af36651..5f9a5ad591c7d 100644 --- a/ext/session/tests/025.phpt +++ b/ext/session/tests/025.phpt @@ -54,6 +54,7 @@ $hnd = new handler; class foo { public $bar = "ok"; + public $yes; function method() { $this->yes++; } } diff --git a/ext/soap/tests/bug70388.phpt b/ext/soap/tests/bug70388.phpt index 87259bf45d50a..8f3e8be766ea1 100644 --- a/ext/soap/tests/bug70388.phpt +++ b/ext/soap/tests/bug70388.phpt @@ -4,6 +4,8 @@ Bug #70388 (SOAP serialize_function_call() type confusion / RCE) soap --FILE-- --EXPECTF-- -Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d +Deprecated: Creation of dynamic property Foo::$private is deprecated in %s on line %d -Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d +Deprecated: Creation of dynamic property Foo::$protected is deprecated in %s on line %d Deprecated: Creation of dynamic property Foo::$notThere is deprecated in %s on line %d object(Foo)#1 (4) { diff --git a/ext/standard/tests/serialize/bug49649_1.phpt b/ext/standard/tests/serialize/bug49649_1.phpt index 6b9c2552451c8..731d794c70010 100644 --- a/ext/standard/tests/serialize/bug49649_1.phpt +++ b/ext/standard/tests/serialize/bug49649_1.phpt @@ -34,7 +34,7 @@ $class = unserialize(base64_decode($serialized)); var_dump($class); ?> --EXPECTF-- -Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d +Deprecated: Creation of dynamic property Foo::$private is deprecated in %s on line %d Deprecated: Creation of dynamic property Foo::$public is deprecated in %s on line %d diff --git a/ext/standard/tests/serialize/bug49649_2.phpt b/ext/standard/tests/serialize/bug49649_2.phpt index 6efcedae050b1..7c96c7bd28b8e 100644 --- a/ext/standard/tests/serialize/bug49649_2.phpt +++ b/ext/standard/tests/serialize/bug49649_2.phpt @@ -34,7 +34,7 @@ $class = unserialize(base64_decode($serialized)); var_dump($class); ?> --EXPECTF-- -Deprecated: Creation of dynamic property Foo::$ is deprecated in %s on line %d +Deprecated: Creation of dynamic property Foo::$protected is deprecated in %s on line %d Deprecated: Creation of dynamic property Foo::$public is deprecated in %s on line %d diff --git a/ext/standard/tests/serialize/unserialize_overwrite_undeclared_protected.phpt b/ext/standard/tests/serialize/unserialize_overwrite_undeclared_protected.phpt index ee9bfab62fe45..d9f44c37a1560 100644 --- a/ext/standard/tests/serialize/unserialize_overwrite_undeclared_protected.phpt +++ b/ext/standard/tests/serialize/unserialize_overwrite_undeclared_protected.phpt @@ -13,7 +13,7 @@ STR; var_dump(unserialize($str)); ?> --EXPECTF-- -Deprecated: Creation of dynamic property Test::$ is deprecated in %s on line %d +Deprecated: Creation of dynamic property Test::$x is deprecated in %s on line %d object(Test)#1 (2) { ["foo"]=> NULL diff --git a/ext/standard/tests/serialize/unserialize_ref_to_overwritten_declared_prop.phpt b/ext/standard/tests/serialize/unserialize_ref_to_overwritten_declared_prop.phpt index f32b0c12e2f26..c4c3c957d3ee8 100644 --- a/ext/standard/tests/serialize/unserialize_ref_to_overwritten_declared_prop.phpt +++ b/ext/standard/tests/serialize/unserialize_ref_to_overwritten_declared_prop.phpt @@ -3,10 +3,10 @@ Trying to create a reference to an overwritten declared property --FILE-- --EXPECTF-- -Notice: unserialize(): Error at offset 51 of 52 bytes in %s on line %d +Notice: unserialize(): Error at offset 36 of 52 bytes in %s on line %d bool(false) diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re index c9dd715f08da2..ab0a13afe9038 100644 --- a/ext/standard/var_unserializer.re +++ b/ext/standard/var_unserializer.re @@ -639,12 +639,12 @@ declared_property: } } else { if (UNEXPECTED(obj->ce->ce_flags & ZEND_ACC_NO_DYNAMIC_PROPERTIES)) { - zend_forbidden_dynamic_property(obj->ce, Z_STR_P(&key)); + zend_throw_error(NULL, "Cannot create dynamic property %s::$%s", + ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key))); goto failure; } else if (!(obj->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) { - if (!zend_deprecated_dynamic_property(obj, Z_STR_P(&key))) { - goto failure; - } + zend_error(E_DEPRECATED, "Creation of dynamic property %s::$%s is deprecated", + ZSTR_VAL(obj->ce->name), zend_get_unmangled_property_name(Z_STR_P(&key))); } int ret = is_property_visibility_changed(obj->ce, &key);