Skip to content

Commit 87f341b

Browse files
committed
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.
1 parent 4bb0dd4 commit 87f341b

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

ext/date/php_date.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,9 @@ PHP_FUNCTION(strtotime)
10351035
}
10361036

10371037
tzi = get_timezone_info();
1038+
if (!tzi) {
1039+
return;
1040+
}
10381041

10391042
now = timelib_time_ctor();
10401043
now->tz_info = tzi;
@@ -1094,6 +1097,9 @@ PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
10941097
timelib_unixtime2gmt(now, (timelib_sll) php_time());
10951098
} else {
10961099
tzi = get_timezone_info();
1100+
if (!tzi) {
1101+
return;
1102+
}
10971103
now->tz_info = tzi;
10981104
now->zone_type = TIMELIB_ZONETYPE_ID;
10991105
timelib_unixtime2local(now, (timelib_sll) php_time());
@@ -1215,6 +1221,9 @@ PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
12151221
timelib_unixtime2gmt(ts, (timelib_sll) timestamp);
12161222
} else {
12171223
tzi = get_timezone_info();
1224+
if (!tzi) {
1225+
return;
1226+
}
12181227
ts->tz_info = tzi;
12191228
ts->zone_type = TIMELIB_ZONETYPE_ID;
12201229
timelib_unixtime2local(ts, (timelib_sll) timestamp);
@@ -1323,6 +1332,9 @@ PHP_FUNCTION(localtime)
13231332
}
13241333

13251334
tzi = get_timezone_info();
1335+
if (!tzi) {
1336+
return;
1337+
}
13261338
ts = timelib_time_ctor();
13271339
ts->tz_info = tzi;
13281340
ts->zone_type = TIMELIB_ZONETYPE_ID;
@@ -1374,6 +1386,9 @@ PHP_FUNCTION(getdate)
13741386
}
13751387

13761388
tzi = get_timezone_info();
1389+
if (!tzi) {
1390+
return;
1391+
}
13771392
ts = timelib_time_ctor();
13781393
ts->tz_info = tzi;
13791394
ts->zone_type = TIMELIB_ZONETYPE_ID;
@@ -2276,6 +2291,9 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size
22762291
tzi = dateobj->time->tz_info;
22772292
} else {
22782293
tzi = get_timezone_info();
2294+
if (!tzi) {
2295+
return 0;
2296+
}
22792297
}
22802298

22812299
now = timelib_time_ctor();
@@ -4464,6 +4482,9 @@ PHP_FUNCTION(date_default_timezone_get)
44644482
ZEND_PARSE_PARAMETERS_NONE();
44654483

44664484
default_tz = get_timezone_info();
4485+
if (!default_tz) {
4486+
return;
4487+
}
44674488
RETVAL_STRING(default_tz->name);
44684489
}
44694490
/* }}} */
@@ -4519,8 +4540,11 @@ static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_su
45194540
altitude = 90 - zenith;
45204541

45214542
/* Initialize time struct */
4522-
t = timelib_time_ctor();
45234543
tzi = get_timezone_info();
4544+
if (!tzi) {
4545+
return;
4546+
}
4547+
t = timelib_time_ctor();
45244548
t->tz_info = tzi;
45254549
t->zone_type = TIMELIB_ZONETYPE_ID;
45264550

@@ -4590,8 +4614,11 @@ PHP_FUNCTION(date_sun_info)
45904614
ZEND_PARSE_PARAMETERS_END();
45914615

45924616
/* Initialize time struct */
4593-
t = timelib_time_ctor();
45944617
tzi = get_timezone_info();
4618+
if (!tzi) {
4619+
return;
4620+
}
4621+
t = timelib_time_ctor();
45954622
t->tz_info = tzi;
45964623
t->zone_type = TIMELIB_ZONETYPE_ID;
45974624
timelib_unixtime2local(t, time);

0 commit comments

Comments
 (0)