Skip to content

Commit e40c9d4

Browse files
committed
Add some missing DatePeriod initialization checks
1 parent 8f61854 commit e40c9d4

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ext/date/php_date.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,6 +4189,7 @@ PHP_METHOD(DatePeriod, getStartDate)
41894189
ZEND_PARSE_PARAMETERS_NONE();
41904190

41914191
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
4192+
DATE_CHECK_INITIALIZED(dpobj->start, DatePeriod);
41924193

41934194
php_date_instantiate(dpobj->start_ce, return_value);
41944195
dateobj = Z_PHPDATE_P(return_value);
@@ -4239,6 +4240,7 @@ PHP_METHOD(DatePeriod, getDateInterval)
42394240
ZEND_PARSE_PARAMETERS_NONE();
42404241

42414242
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
4243+
DATE_CHECK_INITIALIZED(dpobj->interval, DatePeriod);
42424244

42434245
php_date_instantiate(date_ce_interval, return_value);
42444246
diobj = Z_PHPINTERVAL_P(return_value);

ext/date/tests/oo_001.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class _t extends DateTimeZone {
1111
function __construct() {
1212
}
1313
}
14+
class _p extends DatePeriod {
15+
function __construct() {
16+
}
17+
}
1418

1519
$d = new DateTime;
1620
var_dump($d->format("Y-m-d H:i:s"));
@@ -44,6 +48,18 @@ try {
4448
echo $e->getMessage(),"\n";
4549
}
4650

51+
$p = new _p;
52+
try {
53+
var_dump($p->getStartDate());
54+
} catch (Error $e) {
55+
echo $e->getMessage(),"\n";
56+
}
57+
try {
58+
var_dump($p->getDateInterval());
59+
} catch (Error $e) {
60+
echo $e->getMessage(),"\n";
61+
}
62+
4763
echo "DONE\n";
4864
?>
4965
--EXPECTF--
@@ -53,4 +69,6 @@ DateTime::__construct(): Failed to parse time string (1am todax) at position 4 (
5369
string(3) "UTC"
5470
The DateTimeZone object has not been correctly initialized by its constructor
5571
DateTimeZone::__construct(): Unknown or bad timezone (GottaFindThisOne)
72+
The DatePeriod object has not been correctly initialized by its constructor
73+
The DatePeriod object has not been correctly initialized by its constructor
5674
DONE

0 commit comments

Comments
 (0)