Skip to content

Commit

Permalink
Fix tests and review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Aug 19, 2022
1 parent 2de79fe commit a706d6b
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 43 deletions.
38 changes: 8 additions & 30 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions ext/gmp/tests/serialize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions ext/session/tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ error_reporting(E_ALL);

class foo {
public $bar = "ok";
public $yes;
function method() { $this->yes++; }
}

Expand Down
1 change: 1 addition & 0 deletions ext/session/tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ $hnd = new handler;

class foo {
public $bar = "ok";
public $yes;
function method() { $this->yes++; }
}

Expand Down
1 change: 1 addition & 0 deletions ext/session/tests/005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ $hnd = new handler;

class foo {
public $bar = "ok";
public $yes;
function method() { $this->yes++; }
}

Expand Down
1 change: 1 addition & 0 deletions ext/session/tests/023.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ error_reporting(E_ALL);

class foo {
public $bar = "ok";
public $yes;
function method() { $this->yes++; }
}

Expand Down
1 change: 1 addition & 0 deletions ext/session/tests/024.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ $hnd = new handler;

class foo {
public $bar = "ok";
public $yes;
function method() { $this->yes++; }
}

Expand Down
1 change: 1 addition & 0 deletions ext/session/tests/025.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ $hnd = new handler;

class foo {
public $bar = "ok";
public $yes;
function method() { $this->yes++; }
}

Expand Down
2 changes: 2 additions & 0 deletions ext/soap/tests/bug70388.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Bug #70388 (SOAP serialize_function_call() type confusion / RCE)
soap
--FILE--
<?php

#[AllowDynamicProperties]
class MySoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = 0): string {
echo $request, "\n";
Expand Down
1 change: 1 addition & 0 deletions ext/soap/tests/bugs/bug69085.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ soap.wsdl_cache_enabled=0
--FILE--
<?php

#[AllowDynamicProperties]
class MySoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = 0): string {
echo $request, "\n";
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/tests/serialize/bug49649.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ $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::$ 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) {
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/serialize/bug49649_1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/tests/serialize/bug49649_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Trying to create a reference to an overwritten declared property
--FILE--
<?php
$str = <<<STR
O:5:"Error":2:{S:8:"previous";N;S:8:"previous";R:2;}
O:9:"Attribute":1:{s:5:"flags";i:63;s:5:"flags";R:2}
STR;
var_dump(unserialize($str));
?>
--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)
8 changes: 4 additions & 4 deletions ext/standard/var_unserializer.re
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a706d6b

Please sign in to comment.