Skip to content

Commit

Permalink
Add some missing DatePeriod initialization checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 13, 2020
1 parent 8f61854 commit e40c9d4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions ext/date/tests/oo_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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--
Expand All @@ -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

0 comments on commit e40c9d4

Please sign in to comment.