Skip to content

Commit 591bd11

Browse files
committed
Merge remote-tracking branch 'derickr/bug78139-tz-weird' into PHP-8.0
2 parents d8590b1 + d5e5726 commit 591bd11

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ PHP NEWS
44

55
- Date:
66
. Fixed bug #74671 (DST timezone abbreviation has incorrect offset). (Derick)
7+
. Fixed bug #78139 (timezone_open accepts invalid timezone string argument).
8+
(Derick)
79

810
09 Jun 2022, PHP 8.0.20
911

ext/date/php_date.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3428,6 +3428,12 @@ static int timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t t
34283428

34293429
dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
34303430
dummy_t->dst = dst;
3431+
if (!not_found && (*tz != '\0')) {
3432+
php_error_docref(NULL, E_WARNING, "Unknown or bad timezone (%s)", orig_tz);
3433+
timelib_free(dummy_t->tz_abbr);
3434+
efree(dummy_t);
3435+
return FAILURE;
3436+
}
34313437
if (not_found) {
34323438
php_error_docref(NULL, E_WARNING, "Unknown or bad timezone (%s)", orig_tz);
34333439
efree(dummy_t);

ext/date/tests/bug78139.phpt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
--TEST--
2+
Bug #78139 (timezone_open accepts invalid timezone string argument)
3+
--FILE--
4+
<?php
5+
$strings = [
6+
"x",
7+
"x UTC",
8+
"xx UTC",
9+
"xUTC",
10+
"UTCx",
11+
"UTC xx",
12+
];
13+
14+
foreach ($strings as $string)
15+
{
16+
echo "Parsing '{$string}':\n";
17+
18+
$tz = timezone_open($string);
19+
var_dump($tz);
20+
21+
try {
22+
$tz = new \DateTimeZone($string);
23+
} catch (Exception $e) {
24+
echo $e->getMessage(), "\n";
25+
}
26+
27+
echo "\n\n";
28+
}
29+
?>
30+
--EXPECTF--
31+
Parsing 'x':
32+
object(DateTimeZone)#1 (2) {
33+
["timezone_type"]=>
34+
int(2)
35+
["timezone"]=>
36+
string(1) "X"
37+
}
38+
39+
40+
Parsing 'x UTC':
41+
42+
Warning: timezone_open(): Unknown or bad timezone (x UTC) in %sbug78139.php on line %d
43+
bool(false)
44+
DateTimeZone::__construct(): Unknown or bad timezone (x UTC)
45+
46+
47+
Parsing 'xx UTC':
48+
49+
Warning: timezone_open(): Unknown or bad timezone (xx UTC) in %sbug78139.php on line %d
50+
bool(false)
51+
DateTimeZone::__construct(): Unknown or bad timezone (xx UTC)
52+
53+
54+
Parsing 'xUTC':
55+
56+
Warning: timezone_open(): Unknown or bad timezone (xUTC) in %sbug78139.php on line %d
57+
bool(false)
58+
DateTimeZone::__construct(): Unknown or bad timezone (xUTC)
59+
60+
61+
Parsing 'UTCx':
62+
63+
Warning: timezone_open(): Unknown or bad timezone (UTCx) in %sbug78139.php on line %d
64+
bool(false)
65+
DateTimeZone::__construct(): Unknown or bad timezone (UTCx)
66+
67+
68+
Parsing 'UTC xx':
69+
70+
Warning: timezone_open(): Unknown or bad timezone (UTC xx) in %sbug78139.php on line %d
71+
bool(false)
72+
DateTimeZone::__construct(): Unknown or bad timezone (UTC xx)
73+

0 commit comments

Comments
 (0)