com php-src: Fixed #74639 - Added proper clone functionality for DatePeriod and DateInterval: NEWS ext/date/php_date.c ext/date/tests /bug74639.phpt
| From: | Joe Watkins | Date: | Thu, 01 Jun 2017 07:07:11 +0000 |
| Subject: | com php-src: Fixed #74639 - Added proper clone functionality for DatePeriod and DateInterval: NEWS ext/date/php_date.c ext/date/tests /bug74639.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-97972@lists.php.net to get a copy of this message | ||
Commit: 48598a23024eb587127b59bf0490891addfc41ed
Author: andrewnester <andrew.nester.dev@gmail.com> Fri, 26 May 2017 13:56:41 +0300
Committer: Joe Watkins <krakjoe@php.net> Thu, 1 Jun 2017 08:07:11 +0100
Parents: 741769d9337d9c211f3a106f6f171b889d5b70bf
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=48598a23024eb587127b59bf0490891addfc41ed
Log:
Fixed #74639 - Added proper clone functionality for DatePeriod and DateInterval
Bugs:
https://bugs.php.net/74639
Changed paths:
M NEWS
M ext/date/php_date.c
A ext/date/tests/bug74639.phpt
Diff:
diff --git a/NEWS b/NEWS
index ce6b60f..4735dd4 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 c4e5fcb..dd6ca22 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 0000000..43eccc9
--- /dev/null
+++ b/ext/date/tests/bug74639.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Bug #74639 Cloning DatePeriod leads to segfault
+--FILE--
+<?php
+
+$start = new DateTime('2017-05-22 09:00:00');
+$end = new DateTime('2017-08-24 18:00:00');
+$interval = $start->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