]> granicus.if.org Git - php/commitdiff
Make sure properties are initialized before cloning
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 25 Nov 2017 21:51:37 +0000 (22:51 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 25 Nov 2017 21:51:37 +0000 (22:51 +0100)
Now that they are not memset, they need to be explicitly intialized,
as zend_objects_clone_members() destroys the old property values
first.

ext/date/php_date.c
ext/dom/php_dom.c

index b3f409f5f178f4796f2d962ee75069fc4d30db6f..9d6f698db6d9db2e25db6165884378231d28a294 100644 (file)
@@ -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;
index 109f7c127a635bc0718762d4e6d1a8a6a8e4f8e3..aa2add47685d11dca0d909b233f95e44378470e1 100644 (file)
@@ -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);