]> granicus.if.org Git - php/commitdiff
Fix DatePeriod::getEndDate() segfault
authorThomas Punt <tpunt@hotmail.co.uk>
Mon, 7 Mar 2016 09:40:22 +0000 (09:40 +0000)
committerAnatol Belski <ab@php.net>
Fri, 11 Mar 2016 13:08:48 +0000 (14:08 +0100)
ext/date/php_date.c
ext/date/tests/bug71635.phpt [new file with mode: 0644]

index e06ace7f8b811f1f5d378efc357a057d9168a8fc..4cb0ec8ff40d4b24529b719ddcc1bba260de9da9 100644 (file)
@@ -4536,6 +4536,10 @@ PHP_METHOD(DatePeriod, getEndDate)
 
         dpobj = (php_period_obj *)zend_object_store_get_object(getThis() TSRMLS_CC);
 
+        if (!dpobj->end) {
+                return;
+        }
+
         php_date_instantiate(dpobj->start_ce, return_value TSRMLS_CC);
         dateobj = (php_date_obj *)zend_object_store_get_object(return_value TSRMLS_CC);
         dateobj->time = timelib_time_ctor();
diff --git a/ext/date/tests/bug71635.phpt b/ext/date/tests/bug71635.phpt
new file mode 100644 (file)
index 0000000..8c5ae25
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Bug #71635 (segfault in DatePeriod::getEndDate() when no end date has been set)
+--FILE--
+<?php
+date_default_timezone_set('UTC');
+$period = new DatePeriod(new DateTimeImmutable("now"), new DateInterval("P2Y4DT6H8M"), 2);
+
+var_dump($period->getEndDate());
+?>
+--EXPECT--
+NULL
\ No newline at end of file