Skip to content

Commit 7f6e98c

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
2 parents 8f1cbc8 + 4833b84 commit 7f6e98c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

ext/date/php_date.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4765,6 +4765,12 @@ PHP_METHOD(DatePeriod, __construct)
47654765
}
47664766
dpobj->start_ce = date_ce_date;
47674767
} else {
4768+
/* check initialisation */
4769+
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(start)->time, DateTimeInterface);
4770+
if (end) {
4771+
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, DateTimeInterface);
4772+
}
4773+
47684774
/* init */
47694775
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);
47704776

ext/date/tests/bug-gh11416.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Bug GH-11416: Crash with DatePeriod when uninitialised objects are passed in
3+
--INI--
4+
date.timezone=UTC
5+
--FILE--
6+
<?php
7+
$now = new DateTimeImmutable();
8+
9+
$date = (new ReflectionClass(DateTime::class))->newInstanceWithoutConstructor();
10+
try {
11+
new DatePeriod($date, new DateInterval('P1D'), 2);
12+
} catch (Error $e) {
13+
echo get_class($e), ': ', $e->getMessage(), "\n";
14+
}
15+
16+
$date = (new ReflectionClass(DateTime::class))->newInstanceWithoutConstructor();
17+
try {
18+
new DatePeriod($now, new DateInterval('P1D'), $date);
19+
} catch (Error $e) {
20+
echo get_class($e), ': ', $e->getMessage(), "\n";
21+
}
22+
23+
echo "OK\n";
24+
?>
25+
--EXPECT--
26+
Error: The DateTimeInterface object has not been correctly initialized by its constructor
27+
Error: The DateTimeInterface object has not been correctly initialized by its constructor
28+
OK

0 commit comments

Comments
 (0)