summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-11-25 22:51:37 +0100
committerNikita Popov <nikita.ppv@gmail.com>2017-11-25 22:51:37 +0100
commitdcdd4abdb2eb622c72c0b271e4f3a173ca8e6765 (patch)
treea79e458998acc1d7637bce7c8f2d2e4b7c6bed87
parentc9fecf7d879c78f54fde696337b335ccbe34c9cc (diff)
downloadphp-git-dcdd4abdb2eb622c72c0b271e4f3a173ca8e6765.tar.gz
Make sure properties are initialized before cloning
Now that they are not memset, they need to be explicitly intialized, as zend_objects_clone_members() destroys the old property values first.
-rw-r--r--ext/date/php_date.c52
-rw-r--r--ext/dom/php_dom.c14
2 files changed, 18 insertions, 48 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index b3f409f5f1..9d6f698db6 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -2185,28 +2185,21 @@ static void date_register_classes(void) /* {{{ */
REGISTER_PERIOD_CLASS_CONST_STRING("EXCLUDE_START_DATE", PHP_DATE_PERIOD_EXCLUDE_START_DATE);
} /* }}} */
-static inline zend_object *date_object_new_date_ex(zend_class_entry *class_type, int init_props) /* {{{ */
+static zend_object *date_object_new_date(zend_class_entry *class_type) /* {{{ */
{
php_date_obj *intern = zend_object_alloc(sizeof(php_date_obj), class_type);
zend_object_std_init(&intern->std, class_type);
- if (init_props) {
- object_properties_init(&intern->std, class_type);
- }
+ object_properties_init(&intern->std, class_type);
intern->std.handlers = &date_object_handlers_date;
return &intern->std;
} /* }}} */
-static zend_object *date_object_new_date(zend_class_entry *class_type) /* {{{ */
-{
- return date_object_new_date_ex(class_type, 1);
-} /* }}} */
-
static zend_object *date_object_clone_date(zval *this_ptr) /* {{{ */
{
php_date_obj *old_obj = Z_PHPDATE_P(this_ptr);
- php_date_obj *new_obj = php_date_obj_from_obj(date_object_new_date_ex(old_obj->std.ce, 0));
+ php_date_obj *new_obj = php_date_obj_from_obj(date_object_new_date(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
if (!old_obj->time) {
@@ -2314,28 +2307,21 @@ static HashTable *date_object_get_properties(zval *object) /* {{{ */
return props;
} /* }}} */
-static inline zend_object *date_object_new_timezone_ex(zend_class_entry *class_type, int init_props) /* {{{ */
+static zend_object *date_object_new_timezone(zend_class_entry *class_type) /* {{{ */
{
php_timezone_obj *intern = zend_object_alloc(sizeof(php_timezone_obj), class_type);
zend_object_std_init(&intern->std, class_type);
- if (init_props) {
- object_properties_init(&intern->std, class_type);
- }
+ object_properties_init(&intern->std, class_type);
intern->std.handlers = &date_object_handlers_timezone;
return &intern->std;
} /* }}} */
-static zend_object *date_object_new_timezone(zend_class_entry *class_type) /* {{{ */
-{
- return date_object_new_timezone_ex(class_type, 1);
-} /* }}} */
-
static zend_object *date_object_clone_timezone(zval *this_ptr) /* {{{ */
{
php_timezone_obj *old_obj = Z_PHPTIMEZONE_P(this_ptr);
- php_timezone_obj *new_obj = php_timezone_obj_from_obj(date_object_new_timezone_ex(old_obj->std.ce, 0));
+ php_timezone_obj *new_obj = php_timezone_obj_from_obj(date_object_new_timezone(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
if (!old_obj->initialized) {
@@ -2403,28 +2389,21 @@ static HashTable *date_object_get_properties_timezone(zval *object) /* {{{ */
return props;
} /* }}} */
-static inline zend_object *date_object_new_interval_ex(zend_class_entry *class_type, int init_props) /* {{{ */
+static zend_object *date_object_new_interval(zend_class_entry *class_type) /* {{{ */
{
php_interval_obj *intern = zend_object_alloc(sizeof(php_interval_obj), class_type);
zend_object_std_init(&intern->std, class_type);
- if (init_props) {
- object_properties_init(&intern->std, class_type);
- }
+ object_properties_init(&intern->std, class_type);
intern->std.handlers = &date_object_handlers_interval;
return &intern->std;
} /* }}} */
-static zend_object *date_object_new_interval(zend_class_entry *class_type) /* {{{ */
-{
- return date_object_new_interval_ex(class_type, 1);
-} /* }}} */
-
static zend_object *date_object_clone_interval(zval *this_ptr) /* {{{ */
{
php_interval_obj *old_obj = Z_PHPINTERVAL_P(this_ptr);
- php_interval_obj *new_obj = php_interval_obj_from_obj(date_object_new_interval_ex(old_obj->std.ce, 0));
+ php_interval_obj *new_obj = php_interval_obj_from_obj(date_object_new_interval(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
new_obj->initialized = old_obj->initialized;
@@ -2487,29 +2466,22 @@ static HashTable *date_object_get_properties_interval(zval *object) /* {{{ */
return props;
} /* }}} */
-static inline zend_object *date_object_new_period_ex(zend_class_entry *class_type, int init_props) /* {{{ */
+static zend_object *date_object_new_period(zend_class_entry *class_type) /* {{{ */
{
php_period_obj *intern = zend_object_alloc(sizeof(php_period_obj), class_type);
zend_object_std_init(&intern->std, class_type);
- if (init_props) {
- object_properties_init(&intern->std, class_type);
- }
+ object_properties_init(&intern->std, class_type);
intern->std.handlers = &date_object_handlers_period;
return &intern->std;
} /* }}} */
-static zend_object *date_object_new_period(zend_class_entry *class_type) /* {{{ */
-{
- return date_object_new_period_ex(class_type, 1);
-} /* }}} */
-
static zend_object *date_object_clone_period(zval *this_ptr) /* {{{ */
{
php_period_obj *old_obj = Z_PHPPERIOD_P(this_ptr);
- php_period_obj *new_obj = php_period_obj_from_obj(date_object_new_period_ex(old_obj->std.ce, 0));
+ php_period_obj *new_obj = php_period_obj_from_obj(date_object_new_period(old_obj->std.ce));
zend_objects_clone_members(&new_obj->std, &old_obj->std);
new_obj->initialized = old_obj->initialized;
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index 109f7c127a..aa2add4768 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -502,12 +502,12 @@ PHP_FUNCTION(dom_import_simplexml)
}
/* }}} */
-static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool hash_copy);
+static dom_object* dom_objects_set_class(zend_class_entry *class_type);
static zend_object *dom_objects_store_clone_obj(zval *zobject) /* {{{ */
{
dom_object *intern = Z_DOMOBJ_P(zobject);
- dom_object *clone = dom_objects_set_class(intern->std.ce, 0);
+ dom_object *clone = dom_objects_set_class(intern->std.ce);
clone->std.handlers = dom_get_obj_handlers();
@@ -1073,7 +1073,7 @@ void dom_namednode_iter(dom_object *basenode, int ntype, dom_object *intern, xml
}
/* }}} */
-static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool hash_copy) /* {{{ */
+static dom_object* dom_objects_set_class(zend_class_entry *class_type) /* {{{ */
{
dom_object *intern = zend_object_alloc(sizeof(dom_object), class_type);
@@ -1085,9 +1085,7 @@ static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool
intern->prop_handler = zend_hash_find_ptr(&classes, base_class->name);
zend_object_std_init(&intern->std, class_type);
- if (hash_copy) {
- object_properties_init(&intern->std, class_type);
- }
+ object_properties_init(&intern->std, class_type);
return intern;
}
@@ -1096,7 +1094,7 @@ static dom_object* dom_objects_set_class(zend_class_entry *class_type, zend_bool
/* {{{ dom_objects_new */
zend_object *dom_objects_new(zend_class_entry *class_type)
{
- dom_object *intern = dom_objects_set_class(class_type, 1);
+ dom_object *intern = dom_objects_set_class(class_type);
intern->std.handlers = dom_get_obj_handlers();
return &intern->std;
}
@@ -1160,7 +1158,7 @@ zend_object *dom_nnodemap_objects_new(zend_class_entry *class_type) /* {{{ */
dom_object *intern;
dom_nnodemap_object *objmap;
- intern = dom_objects_set_class(class_type, 1);
+ intern = dom_objects_set_class(class_type);
intern->ptr = emalloc(sizeof(dom_nnodemap_object));
objmap = (dom_nnodemap_object *)intern->ptr;
ZVAL_UNDEF(&objmap->baseobj_zv);