From 87f341b1c2841062128290e56991924c6f73a5bd Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Tue, 26 Apr 2022 16:43:30 +0100 Subject: [PATCH] Return early when the timezone info is NULL. The guess_timezone function does throw an error, but throwing an error doesn't immediate make the PHP_FUNCTION return. This check is really only necessary for distributions that patch PHP's timelib to use system tzdata, but not correct enough to account for their implementation to guarantee to return a timezone. --- ext/date/php_date.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 5d0b57eab25..a0dcdeb1c12 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -1035,6 +1035,9 @@ PHP_FUNCTION(strtotime) } tzi = get_timezone_info(); + if (!tzi) { + return; + } now = timelib_time_ctor(); now->tz_info = tzi; @@ -1094,6 +1097,9 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt) timelib_unixtime2gmt(now, (timelib_sll) php_time()); } else { tzi = get_timezone_info(); + if (!tzi) { + return; + } now->tz_info = tzi; now->zone_type = TIMELIB_ZONETYPE_ID; timelib_unixtime2local(now, (timelib_sll) php_time()); @@ -1215,6 +1221,9 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt) timelib_unixtime2gmt(ts, (timelib_sll) timestamp); } else { tzi = get_timezone_info(); + if (!tzi) { + return; + } ts->tz_info = tzi; ts->zone_type = TIMELIB_ZONETYPE_ID; timelib_unixtime2local(ts, (timelib_sll) timestamp); @@ -1323,6 +1332,9 @@ PHP_FUNCTION(localtime) } tzi = get_timezone_info(); + if (!tzi) { + return; + } ts = timelib_time_ctor(); ts->tz_info = tzi; ts->zone_type = TIMELIB_ZONETYPE_ID; @@ -1374,6 +1386,9 @@ PHP_FUNCTION(getdate) } tzi = get_timezone_info(); + if (!tzi) { + return; + } ts = timelib_time_ctor(); ts->tz_info = tzi; ts->zone_type = TIMELIB_ZONETYPE_ID; @@ -2276,6 +2291,9 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size tzi = dateobj->time->tz_info; } else { tzi = get_timezone_info(); + if (!tzi) { + return 0; + } } now = timelib_time_ctor(); @@ -4464,6 +4482,9 @@ PHP_FUNCTION(date_default_timezone_get) ZEND_PARSE_PARAMETERS_NONE(); default_tz = get_timezone_info(); + if (!default_tz) { + return; + } RETVAL_STRING(default_tz->name); } /* }}} */ @@ -4519,8 +4540,11 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su altitude = 90 - zenith; /* Initialize time struct */ - t = timelib_time_ctor(); tzi = get_timezone_info(); + if (!tzi) { + return; + } + t = timelib_time_ctor(); t->tz_info = tzi; t->zone_type = TIMELIB_ZONETYPE_ID; @@ -4590,8 +4614,11 @@ PHP_FUNCTION(date_sun_info) ZEND_PARSE_PARAMETERS_END(); /* Initialize time struct */ - t = timelib_time_ctor(); tzi = get_timezone_info(); + if (!tzi) { + return; + } + t = timelib_time_ctor(); t->tz_info = tzi; t->zone_type = TIMELIB_ZONETYPE_ID; timelib_unixtime2local(t, time);