From e40c9d49184d2ce93392a09033dbe5193d36e55f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 13 Aug 2020 17:18:50 +0200 Subject: [PATCH] Add some missing DatePeriod initialization checks --- ext/date/php_date.c | 2 ++ ext/date/tests/oo_001.phpt | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index d81bc1659a..0892439a06 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -4189,6 +4189,7 @@ PHP_METHOD(DatePeriod, getStartDate) ZEND_PARSE_PARAMETERS_NONE(); dpobj = Z_PHPPERIOD_P(ZEND_THIS); + DATE_CHECK_INITIALIZED(dpobj->start, DatePeriod); php_date_instantiate(dpobj->start_ce, return_value); dateobj = Z_PHPDATE_P(return_value); @@ -4239,6 +4240,7 @@ PHP_METHOD(DatePeriod, getDateInterval) ZEND_PARSE_PARAMETERS_NONE(); dpobj = Z_PHPPERIOD_P(ZEND_THIS); + DATE_CHECK_INITIALIZED(dpobj->interval, DatePeriod); php_date_instantiate(date_ce_interval, return_value); diobj = Z_PHPINTERVAL_P(return_value); diff --git a/ext/date/tests/oo_001.phpt b/ext/date/tests/oo_001.phpt index 1d8af7f933..2c06a2b45c 100644 --- a/ext/date/tests/oo_001.phpt +++ b/ext/date/tests/oo_001.phpt @@ -11,6 +11,10 @@ class _t extends DateTimeZone { function __construct() { } } +class _p extends DatePeriod { + function __construct() { + } +} $d = new DateTime; var_dump($d->format("Y-m-d H:i:s")); @@ -44,6 +48,18 @@ try { echo $e->getMessage(),"\n"; } +$p = new _p; +try { + var_dump($p->getStartDate()); +} catch (Error $e) { + echo $e->getMessage(),"\n"; +} +try { + var_dump($p->getDateInterval()); +} catch (Error $e) { + echo $e->getMessage(),"\n"; +} + echo "DONE\n"; ?> --EXPECTF-- @@ -53,4 +69,6 @@ DateTime::__construct(): Failed to parse time string (1am todax) at position 4 ( string(3) "UTC" The DateTimeZone object has not been correctly initialized by its constructor DateTimeZone::__construct(): Unknown or bad timezone (GottaFindThisOne) +The DatePeriod object has not been correctly initialized by its constructor +The DatePeriod object has not been correctly initialized by its constructor DONE -- 2.40.0