Skip to content

Commit

Permalink
Return early when the timezone info is NULL.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
derickr committed Apr 26, 2022
1 parent 4bb0dd4 commit 87f341b
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,9 @@ PHP_FUNCTION(strtotime)
}

tzi = get_timezone_info();
if (!tzi) {
return;
}

now = timelib_time_ctor();
now->tz_info = tzi;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
/* }}} */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 87f341b

Please sign in to comment.