From f752e23cff71d21abec80bfa9fbc62ea1b702a0d Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Wed, 11 Sep 2024 15:46:02 +0100 Subject: [PATCH] Fix GH-15582: Crash when not calling parent constructor of DateTimeZone --- NEWS | 4 ++++ ext/date/php_date.c | 8 +++++++- ext/date/tests/bug-gh15582.phpt | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ext/date/tests/bug-gh15582.phpt diff --git a/NEWS b/NEWS index f09ad6dc622..593ec182948 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 87dd9177491..5f21fea8043 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -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) { diff --git a/ext/date/tests/bug-gh15582.phpt b/ext/date/tests/bug-gh15582.phpt new file mode 100644 index 00000000000..ab03e190e4b --- /dev/null +++ b/ext/date/tests/bug-gh15582.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug GH-15582: Crash when not calling parent constructor of DateTimeZone +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECT-- +Error: The DateTimeZone object has not been correctly initialized by its constructor