File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ PHP NEWS
25
25
(timwolla)
26
26
. Fixed double-free when assigning to $errors fails when using
27
27
the Uri\WhatWg\Url parser. (timwolla)
28
+ . Reject out-of-range ports when using the Uri\Rfc3986\Uri parser.
29
+ (timwolla)
28
30
. Clean up naming of internal API. (timwolla)
29
31
30
32
28 Aug 2025, PHP 8.5.0beta2
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ Test that out of range ports are rejected
3
+ --EXTENSIONS--
4
+ uri
5
+ --FILE--
6
+ <?php
7
+
8
+ try {
9
+ new \Uri \Rfc3986 \Uri ('https://example.com:987654321987654321987654321987654321 ' );
10
+ } catch (Throwable $ e ) {
11
+ echo $ e ::class, ": " , $ e ->getMessage (), PHP_EOL ;
12
+ }
13
+
14
+ ?>
15
+ --EXPECT--
16
+ Uri\InvalidUriException: The port is out of range
Original file line number Diff line number Diff line change @@ -190,11 +190,11 @@ ZEND_ATTRIBUTE_NONNULL static zend_result php_uri_parser_rfc3986_host_read(const
190
190
return SUCCESS ;
191
191
}
192
192
193
- ZEND_ATTRIBUTE_NONNULL static size_t str_to_int (const char * str , size_t len )
193
+ ZEND_ATTRIBUTE_NONNULL static zend_ulong str_to_int (const char * str , size_t len )
194
194
{
195
- size_t result = 0 ;
195
+ zend_ulong result = 0 ;
196
196
197
- for (size_t i = 0 ; i < len ; ++ i ) {
197
+ for (zend_ulong i = 0 ; i < len ; ++ i ) {
198
198
result = result * 10 + (str [i ] - '0' );
199
199
}
200
200
@@ -319,6 +319,20 @@ php_uri_parser_rfc3986_uris *php_uri_parser_rfc3986_parse_ex(const char *uri_str
319
319
/* Make the resulting URI independent of the 'uri_str'. */
320
320
uriMakeOwnerMmA (& uri , mm );
321
321
322
+ if (has_text_range (& uri .portText )) {
323
+ size_t port_length = get_text_range_length (& uri .portText );
324
+ if (
325
+ port_length > 5
326
+ || str_to_int (uri .portText .first , port_length ) > 65535
327
+ ) {
328
+ if (!silent ) {
329
+ zend_throw_exception (uri_invalid_uri_exception_ce , "The port is out of range" , 0 );
330
+ }
331
+
332
+ goto fail ;
333
+ }
334
+ }
335
+
322
336
php_uri_parser_rfc3986_uris * uriparser_uris = uriparser_create_uris ();
323
337
uriparser_uris -> uri = uri ;
324
338
You can’t perform that action at this time.
0 commit comments