Skip to content

Commit 2e6b317

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
2 parents eecbb60 + 25744dd commit 2e6b317

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

ext/date/php_date.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,6 +3609,12 @@ static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t
36093609
}
36103610

36113611
dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
3612+
if ((dummy_t->z >= (100 * 60 * 60)) || (dummy_t->z <= (-100 * 60 * 60))) {
3613+
php_error_docref(NULL, E_WARNING, "Timezone offset is out of range (%s)", orig_tz);
3614+
timelib_free(dummy_t->tz_abbr);
3615+
efree(dummy_t);
3616+
return FAILURE;
3617+
}
36123618
dummy_t->dst = dst;
36133619
if (!not_found && (*tz != '\0')) {
36143620
php_error_docref(NULL, E_WARNING, "Unknown or bad timezone (%s)", orig_tz);

ext/date/tests/bug-gh9763.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test bug GH-9763: DateTimeZone ctr mishandles input and adds null byte if the argument is an offset larger than 100*60 minutes
3+
--FILE--
4+
<?php
5+
date_default_timezone_set('UTC');
6+
7+
foreach ( [ '+99:60', '+99:62', '-99:62', '-99:60', '+9960', '-9960', '+9959', '-9959' ] as $test )
8+
{
9+
echo "Testing {$test}: ";
10+
try {
11+
$d = new DateTimeZone($test);
12+
echo $d->getName(), "\n";
13+
} catch (Exception $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
}
17+
18+
19+
?>
20+
--EXPECT--
21+
Testing +99:60: DateTimeZone::__construct(): Timezone offset is out of range (+99:60)
22+
Testing +99:62: DateTimeZone::__construct(): Timezone offset is out of range (+99:62)
23+
Testing -99:62: DateTimeZone::__construct(): Timezone offset is out of range (-99:62)
24+
Testing -99:60: DateTimeZone::__construct(): Timezone offset is out of range (-99:60)
25+
Testing +9960: DateTimeZone::__construct(): Timezone offset is out of range (+9960)
26+
Testing -9960: DateTimeZone::__construct(): Timezone offset is out of range (-9960)
27+
Testing +9959: +99:59
28+
Testing -9959: -99:59

0 commit comments

Comments
 (0)