Skip to content

Commit 15ca366

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20366 ext/uri: Do not throw ValueError on null-byte (#20489)
2 parents e28e891 + 9743977 commit 15ca366

23 files changed

+389
-78
lines changed

ext/uri/php_uri.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static void create_rfc3986_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor
377377
zend_object *base_url_object = NULL;
378378

379379
ZEND_PARSE_PARAMETERS_START(1, 2)
380-
Z_PARAM_PATH_STR(uri_str)
380+
Z_PARAM_STR(uri_str)
381381
Z_PARAM_OPTIONAL
382382
Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, php_uri_ce_rfc3986_uri)
383383
ZEND_PARSE_PARAMETERS_END();
@@ -490,7 +490,7 @@ static void create_whatwg_uri(INTERNAL_FUNCTION_PARAMETERS, bool is_constructor)
490490
zval *errors = NULL;
491491

492492
ZEND_PARSE_PARAMETERS_START(1, 3)
493-
Z_PARAM_PATH_STR(uri_str)
493+
Z_PARAM_STR(uri_str)
494494
Z_PARAM_OPTIONAL
495495
Z_PARAM_OBJ_OF_CLASS_OR_NULL(base_url_object, php_uri_ce_whatwg_url)
496496
Z_PARAM_ZVAL(errors)
@@ -553,7 +553,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, withUserInfo)
553553
zend_string *value;
554554

555555
ZEND_PARSE_PARAMETERS_START(1, 1)
556-
Z_PARAM_PATH_STR_OR_NULL(value)
556+
Z_PARAM_STR_OR_NULL(value)
557557
ZEND_PARSE_PARAMETERS_END();
558558

559559
zval zv;
@@ -769,7 +769,7 @@ PHP_METHOD(Uri_Rfc3986_Uri, resolve)
769769
zend_string *uri_str;
770770

771771
ZEND_PARSE_PARAMETERS_START(1, 1)
772-
Z_PARAM_PATH_STR(uri_str)
772+
Z_PARAM_STR(uri_str)
773773
ZEND_PARSE_PARAMETERS_END();
774774

775775
php_uri_instantiate_uri(INTERNAL_FUNCTION_PARAM_PASSTHRU,
@@ -956,7 +956,7 @@ PHP_METHOD(Uri_WhatWg_Url, resolve)
956956
zval *errors = NULL;
957957

958958
ZEND_PARSE_PARAMETERS_START(1, 2)
959-
Z_PARAM_PATH_STR(uri_str)
959+
Z_PARAM_STR(uri_str)
960960
Z_PARAM_OPTIONAL
961961
Z_PARAM_ZVAL(errors)
962962
ZEND_PARSE_PARAMETERS_END();

ext/uri/php_uri_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void php_uri_property_write_str_helper(INTERNAL_FUNCTION_PARAMETERS, php_uri_pro
9696
zend_string *value;
9797

9898
ZEND_PARSE_PARAMETERS_START(1, 1)
99-
Z_PARAM_PATH_STR(value)
99+
Z_PARAM_STR(value)
100100
ZEND_PARSE_PARAMETERS_END();
101101

102102
zval zv;
@@ -110,7 +110,7 @@ void php_uri_property_write_str_or_null_helper(INTERNAL_FUNCTION_PARAMETERS, php
110110
zend_string *value;
111111

112112
ZEND_PARSE_PARAMETERS_START(1, 1)
113-
Z_PARAM_PATH_STR_OR_NULL(value)
113+
Z_PARAM_STR_OR_NULL(value)
114114
ZEND_PARSE_PARAMETERS_END();
115115

116116
zval zv;

ext/uri/tests/035.phpt

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Test Uri\Rfc3986\Uri component modification - path - null byte
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$uri = Uri\Rfc3986\Uri::parse("https://example.com");
9+
10+
try {
11+
$uri->withPath("/\0foo");
12+
} catch (Throwable $e) {
13+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Uri\InvalidUriException: The specified path is malformed

ext/uri/tests/rfc3986/parsing/basic_error_null_byte1.phpt renamed to ext/uri/tests/rfc3986/parsing/basic_error_null_byte.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Test Uri\Rfc3986\Uri parsing - basic - URI contains null byte
55

66
try {
77
new Uri\Rfc3986\Uri("https://exam\0ple.com");
8-
} catch (ValueError $e) {
8+
} catch (Throwable $e) {
99
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
1010
}
1111

1212
?>
1313
--EXPECT--
14-
ValueError: Uri\Rfc3986\Uri::__construct(): Argument #1 ($uri) must not contain any null bytes
14+
Uri\InvalidUriException: The specified URI is malformed

ext/uri/tests/rfc3986/parsing/basic_error_null_byte2.phpt

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Test Uri\Rfc3986\Uri reference resolution - resolve() - null byte
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$uri = Uri\Rfc3986\Uri::parse("https://example.com");
9+
10+
try {
11+
$uri->resolve("/f\0o");
12+
} catch (Throwable $e) {
13+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Uri\InvalidUriException: The specified URI is malformed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Test Uri\WhatWg\Url component modification - fragment - null byte
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$url1 = Uri\WhatWg\Url::parse("https://example.com");
9+
$url2 = $url1->withFragment("frag\0ment");
10+
11+
var_dump($url1->getFragment());
12+
var_dump($url2->getFragment());
13+
var_dump($url2->toAsciiString());
14+
15+
?>
16+
--EXPECT--
17+
NULL
18+
string(11) "frag%00ment"
19+
string(32) "https://example.com/#frag%00ment"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Test Uri\WhatWg\Url component modification - host - null byte
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$url = Uri\WhatWg\Url::parse("https://example.com");
9+
10+
try {
11+
$url->withHost("h\0st");
12+
} catch (Throwable $e) {
13+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Uri\WhatWg\InvalidUrlException: The specified host is malformed (DomainInvalidCodePoint)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Test Uri\WhatWg\Url component modification - password - null byte
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$url1 = Uri\WhatWg\Url::parse("https://example.com");
9+
$url2 = $url1->withPassword("pass\0word");
10+
11+
var_dump($url1->getPassword());
12+
var_dump($url2->getPassword());
13+
var_dump($url2->toAsciiString());
14+
15+
16+
?>
17+
--EXPECT--
18+
NULL
19+
string(11) "pass%00word"
20+
string(33) "https://:pass%00word@example.com/"

0 commit comments

Comments
 (0)