Skip to content

Commit e700804

Browse files
committed
Merge remote-tracking branch 'derickr/phpGH-15582' into PHP-8.2
2 parents 7a67fb0 + f752e23 commit e700804

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.2.25
44

5+
- Date:
6+
. Fixed bug GH-15582: Crash when not calling parent constructor of
7+
DateTimeZone. (Derick)
8+
59
- SOAP:
610
. Fixed bug #62900 (Wrong namespace on xsd import error message). (nielsdos)
711

ext/date/php_date.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,11 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t
687687
(offset->offset < 0) ? '-' : '+',
688688
abs(offset->offset / 3600),
689689
abs((offset->offset % 3600) / 60));
690-
} else {
690+
} else if (t->zone_type == TIMELIB_ZONETYPE_ID) {
691691
offset = timelib_get_time_zone_info(t->sse, t->tz_info);
692+
} else {
693+
/* Shouldn't happen, but code defensively */
694+
offset = timelib_time_offset_ctor();
692695
}
693696
}
694697

@@ -2418,6 +2421,9 @@ PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, siz
24182421
new_dst = tzobj->tzi.z.dst;
24192422
new_abbr = timelib_strdup(tzobj->tzi.z.abbr);
24202423
break;
2424+
default:
2425+
zend_throw_error(NULL, "The DateTimeZone object has not been correctly initialized by its constructor");
2426+
return 0;
24212427
}
24222428
type = tzobj->type;
24232429
} else if (dateobj->time->tz_info) {

ext/date/tests/bug-gh15582.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug GH-15582: Crash when not calling parent constructor of DateTimeZone
3+
--FILE--
4+
<?php
5+
class MyDateTimeZone extends DateTimeZone
6+
{
7+
function __construct()
8+
{
9+
}
10+
}
11+
12+
$mdtz = new MyDateTimeZone();
13+
$fusion = $mdtz;
14+
try {
15+
date_create("2005-07-14 22:30:41", $fusion);
16+
} catch (Error $e) {
17+
echo get_class($e), ': ', $e->getMessage(), "\n";
18+
}
19+
?>
20+
--EXPECT--
21+
Error: The DateTimeZone object has not been correctly initialized by its constructor

0 commit comments

Comments
 (0)