Skip to content

Commit 44f04b6

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: Fix GH-25019: Uri\Rfc3986\Uri rejects a port with leading zeros as out of range
2 parents a4ea210 + b6df822 commit 44f04b6

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Test Uri\Rfc3986\Uri parsing - port - leading zeros
3+
--FILE--
4+
<?php
5+
6+
$uri = Uri\Rfc3986\Uri::parse("http://example.com:000000000000000000008080");
7+
8+
var_dump($uri);
9+
var_dump($uri->toRawString());
10+
var_dump($uri->toString());
11+
12+
?>
13+
--EXPECTF--
14+
object(Uri\Rfc3986\Uri)#%d (%d) {
15+
["scheme"]=>
16+
string(4) "http"
17+
["username"]=>
18+
NULL
19+
["password"]=>
20+
NULL
21+
["host"]=>
22+
string(11) "example.com"
23+
["port"]=>
24+
int(8080)
25+
["path"]=>
26+
string(0) ""
27+
["query"]=>
28+
NULL
29+
["fragment"]=>
30+
NULL
31+
}
32+
string(43) "http://example.com:000000000000000000008080"
33+
string(23) "http://example.com:8080"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Test Uri\Rfc3986\Uri parsing - port - leading zeros - zero
3+
--FILE--
4+
<?php
5+
6+
$uri = Uri\Rfc3986\Uri::parse("http://example.com:000000000000000000000000");
7+
8+
var_dump($uri);
9+
var_dump($uri->toRawString());
10+
var_dump($uri->toString());
11+
12+
?>
13+
--EXPECTF--
14+
object(Uri\Rfc3986\Uri)#%d (%d) {
15+
["scheme"]=>
16+
string(4) "http"
17+
["username"]=>
18+
NULL
19+
["password"]=>
20+
NULL
21+
["host"]=>
22+
string(11) "example.com"
23+
["port"]=>
24+
int(0)
25+
["path"]=>
26+
string(0) ""
27+
["query"]=>
28+
NULL
29+
["fragment"]=>
30+
NULL
31+
}
32+
string(43) "http://example.com:000000000000000000000000"
33+
string(20) "http://example.com:0"

‎ext/uri/uri_parser_rfc3986.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ static zend_result php_uri_parser_rfc3986_host_write(void *uri, const zval *valu
385385

386386
ZEND_ATTRIBUTE_NONNULL static zend_long port_str_to_zend_long_checked(const char *str, const size_t len)
387387
{
388+
while (len > 1 && *str == '0') {
389+
str++;
390+
len--;
391+
}
392+
388393
if (len > MAX_LENGTH_OF_LONG) {
389394
return -1;
390395
}

0 commit comments

Comments
 (0)