Skip to content

Commit 9ebdbe2

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents a0749bb + e700804 commit 9ebdbe2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/date/php_date.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,11 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t
704704
(offset->offset < 0) ? '-' : '+',
705705
abs(offset->offset / 3600),
706706
abs((offset->offset % 3600) / 60));
707-
} else {
707+
} else if (t->zone_type == TIMELIB_ZONETYPE_ID) {
708708
offset = timelib_get_time_zone_info(t->sse, t->tz_info);
709+
} else {
710+
/* Shouldn't happen, but code defensively */
711+
offset = timelib_time_offset_ctor();
709712
}
710713
}
711714

@@ -2446,6 +2449,9 @@ PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, siz
24462449
new_dst = tzobj->tzi.z.dst;
24472450
new_abbr = timelib_strdup(tzobj->tzi.z.abbr);
24482451
break;
2452+
default:
2453+
zend_throw_error(NULL, "The DateTimeZone object has not been correctly initialized by its constructor");
2454+
return 0;
24492455
}
24502456
type = tzobj->type;
24512457
} 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)