Skip to content

Commit 47b9ea1

Browse files
committed
Merge remote-tracking branch 'derickr/gh9763' into PHP-8.0
2 parents cefb228 + 7b48053 commit 47b9ea1

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
@@ -3438,6 +3438,12 @@ static int timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t t
34383438
}
34393439

34403440
dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
3441+
if ((dummy_t->z >= (100 * 60 * 60)) || (dummy_t->z <= (-100 * 60 * 60))) {
3442+
php_error_docref(NULL, E_WARNING, "Timezone offset is out of range (%s)", orig_tz);
3443+
timelib_free(dummy_t->tz_abbr);
3444+
efree(dummy_t);
3445+
return FAILURE;
3446+
}
34413447
dummy_t->dst = dst;
34423448
if (!not_found && (*tz != '\0')) {
34433449
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)