From: andrewnester Date: Fri, 26 May 2017 10:56:41 +0000 (+0300) Subject: Fixed #74639 - Added proper clone functionality for DatePeriod and DateInterval X-Git-Tag: php-7.2.0alpha1~26^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=48598a23024eb587127b59bf0490891addfc41ed;p=php Fixed #74639 - Added proper clone functionality for DatePeriod and DateInterval --- diff --git a/NEWS b/NEWS index ce6b60f5f6..4735dd47a4 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,10 @@ PHP NEWS properties). (Laruence) . Fixed misparsing of abstract unix domain socket names. (Sara) +- Date: + . Fixed bug #74639 (implement clone for DatePeriod and DateInterval). + (andrewnester) + - Mbstring: . Add oniguruma upstream fix (CVE-2017-9224, CVE-2017-9226, CVE-2017-9227, CVE-2017-9228, CVE-2017-9229) (Remi, Mamoru TASAKA) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index c4e5fcb50b..dd6ca22fba 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2397,8 +2397,11 @@ static zend_object *date_object_clone_interval(zval *this_ptr) /* {{{ */ php_interval_obj *new_obj = php_interval_obj_from_obj(date_object_new_interval_ex(old_obj->std.ce, 0)); zend_objects_clone_members(&new_obj->std, &old_obj->std); + new_obj->initialized = old_obj->initialized; + if (old_obj->diff) { + new_obj->diff = timelib_rel_time_clone(old_obj->diff); + } - /** FIX ME ADD CLONE STUFF **/ return &new_obj->std; } /* }}} */ @@ -2481,8 +2484,23 @@ static zend_object *date_object_clone_period(zval *this_ptr) /* {{{ */ php_period_obj *new_obj = php_period_obj_from_obj(date_object_new_period_ex(old_obj->std.ce, 0)); zend_objects_clone_members(&new_obj->std, &old_obj->std); - - /** FIX ME ADD CLONE STUFF **/ + new_obj->initialized = old_obj->initialized; + new_obj->recurrences = old_obj->recurrences; + new_obj->include_start_date = old_obj->include_start_date; + new_obj->start_ce = old_obj->start_ce; + + if (old_obj->start) { + new_obj->start = timelib_time_clone(old_obj->start); + } + if (old_obj->current) { + new_obj->current = timelib_time_clone(old_obj->current); + } + if (old_obj->end) { + new_obj->end = timelib_time_clone(old_obj->end); + } + if (old_obj->interval) { + new_obj->interval = timelib_rel_time_clone(old_obj->interval); + } return &new_obj->std; } /* }}} */ diff --git a/ext/date/tests/bug74639.phpt b/ext/date/tests/bug74639.phpt new file mode 100644 index 0000000000..43eccc974d --- /dev/null +++ b/ext/date/tests/bug74639.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #74639 Cloning DatePeriod leads to segfault +--FILE-- +diff($end); + +$period = new DatePeriod($start, $interval, $end); +$clonedPeriod = clone $period; +$clonedInterval = clone $interval; + +if ($period->getStartDate() != $clonedPeriod->getStartDate()) { + echo "failure\n"; +} + +if ($period->getEndDate() != $clonedPeriod->getEndDate()) { + echo "failure\n"; +} + +if ($period->getDateInterval() != $clonedPeriod->getDateInterval()) { + echo "failure\n"; +} + +if ($interval->format('Y-m-d H:i:s') != $clonedInterval->format('Y-m-d H:i:s')) { + echo "failure\n"; +} + +echo 'success'; +?> +--EXPECT-- +success