Skip to content

Commit fac3fbc

Browse files
committed
Fix OOB read due to timezone_open() with 5 digit offset
This has been reported as bug #78984, and is generally and properly fixed as of timelib 2020.3 (PHP-8.0). However, it is not fixed in PHP-7.4, where the test results in an OOB read, and an unterminated C string when calling `::getName()`. Therefore, we apply a minimal fix which just avoids this dangerous behavior.
1 parent af8fcce commit fac3fbc

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

ext/date/lib/parse_date.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,9 @@ static timelib_long timelib_parse_tz_cor(char **ptr)
766766
return sHOUR(tmp / 100) + sMIN(tmp % 100);
767767
}
768768
case 5: /* HH:MM */
769+
if (begin[2] != ':') {
770+
return 0;
771+
}
769772
tmp = sHOUR(strtol(begin, NULL, 10)) + sMIN(strtol(begin + 3, NULL, 10));
770773
return tmp;
771774
}

ext/date/lib/parse_date.re

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,9 @@ static timelib_long timelib_parse_tz_cor(char **ptr)
764764
return sHOUR(tmp / 100) + sMIN(tmp % 100);
765765
}
766766
case 5: /* HH:MM */
767+
if (begin[2] != ':') {
768+
return 0;
769+
}
767770
tmp = sHOUR(strtol(begin, NULL, 10)) + sMIN(strtol(begin + 3, NULL, 10));
768771
return tmp;
769772
}

ext/date/tests/bug78984.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #78984 (DateTimeZone accepting invalid UTC timezones)
3+
--FILE--
4+
<?php
5+
$tz = @timezone_open('+30157');
6+
if ($tz) {
7+
// relevant case for quick fix
8+
var_dump($tz->getName());
9+
} else {
10+
// dummy case for proper fix
11+
var_dump("+00:00");
12+
}
13+
?>
14+
--EXPECT--
15+
string(6) "+00:00"

0 commit comments

Comments
 (0)