Fix GH-15582: Crash when not calling parent constructor of DateTimeZone

This commit is contained in:
Derick Rethans 2024-09-11 15:46:02 +01:00
parent 7a67fb0315
commit f752e23cff
No known key found for this signature in database
GPG Key ID: 910DEB46F53EA312
3 changed files with 32 additions and 1 deletions

4
NEWS
View File

@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.2.25
- Date:
. Fixed bug GH-15582: Crash when not calling parent constructor of
DateTimeZone. (Derick)
- SOAP:
. Fixed bug #62900 (Wrong namespace on xsd import error message). (nielsdos)

View File

@ -687,8 +687,11 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t
(offset->offset < 0) ? '-' : '+',
abs(offset->offset / 3600),
abs((offset->offset % 3600) / 60));
} else {
} else if (t->zone_type == TIMELIB_ZONETYPE_ID) {
offset = timelib_get_time_zone_info(t->sse, t->tz_info);
} else {
/* Shouldn't happen, but code defensively */
offset = timelib_time_offset_ctor();
}
}
@ -2418,6 +2421,9 @@ PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, siz
new_dst = tzobj->tzi.z.dst;
new_abbr = timelib_strdup(tzobj->tzi.z.abbr);
break;
default:
zend_throw_error(NULL, "The DateTimeZone object has not been correctly initialized by its constructor");
return 0;
}
type = tzobj->type;
} else if (dateobj->time->tz_info) {

View File

@ -0,0 +1,21 @@
--TEST--
Bug GH-15582: Crash when not calling parent constructor of DateTimeZone
--FILE--
<?php
class MyDateTimeZone extends DateTimeZone
{
function __construct()
{
}
}
$mdtz = new MyDateTimeZone();
$fusion = $mdtz;
try {
date_create("2005-07-14 22:30:41", $fusion);
} catch (Error $e) {
echo get_class($e), ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
Error: The DateTimeZone object has not been correctly initialized by its constructor