Skip to content

Fix #80114: parse_url does not accept URLs with port 0 #6152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ext/standard/tests/url/parse_url_basic_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,15 @@ echo "Done";
string(3) "%:x"
}

--> https://example.com:0/: array(3) {
["scheme"]=>
string(5) "https"
["host"]=>
string(11) "example.com"
["path"]=>
string(1) "/"
}

--> http:///blah.com: bool(false)

--> http://:80: bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ echo "Done";
--> / : NULL
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : string(5) "https"
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ echo "Done";
--> / : NULL
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : string(11) "example.com"
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ echo "Done";
--> / : NULL
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : NULL
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ echo "Done";
--> / : NULL
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : NULL
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ echo "Done";
--> / : NULL
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : NULL
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ echo "Done";
--> / : string(1) "/"
--> /rest/Users?filter={"id":"123"} : string(11) "/rest/Users"
--> %:x : string(3) "%:x"
--> https://example.com:0/ : string(1) "/"
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ echo "Done";
--> / : NULL
--> /rest/Users?filter={"id":"123"} : string(19) "filter={"id":"123"}"
--> %:x : NULL
--> https://example.com:0/ : NULL
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/parse_url_basic_009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ echo "Done";
--> / : NULL
--> /rest/Users?filter={"id":"123"} : NULL
--> %:x : NULL
--> https://example.com:0/ : NULL
--> http:///blah.com : bool(false)
--> http://:80 : bool(false)
--> http://user@:80 : bool(false)
Expand Down
9 changes: 9 additions & 0 deletions ext/standard/tests/url/parse_url_unterminated.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ echo "Done";
string(3) "%:x"
}

--> https://example.com:0/: array(3) {
["scheme"]=>
string(5) "https"
["host"]=>
string(11) "example.com"
["path"]=>
string(1) "/"
}

--> http:///blah.com: bool(false)

--> http://:80: bool(false)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/url/urls.inc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ $urls = array(
'/',
'/rest/Users?filter={"id":"123"}',
'%:x',
'https://example.com:0/',

// Severely malformed URLs that do not parse:
'http:///blah.com',
Expand Down
10 changes: 6 additions & 4 deletions ext/standard/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)

if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) {
zend_long port;
char *end;
memcpy(port_buf, p, (pp - p));
port_buf[pp - p] = '\0';
port = ZEND_STRTOL(port_buf, NULL, 10);
if (port > 0 && port <= 65535) {
port = ZEND_STRTOL(port_buf, &end, 10);
if (port >= 0 && port <= 65535 && end != port_buf) {
ret->port = (unsigned short) port;
if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
s += 2;
Expand Down Expand Up @@ -258,10 +259,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
return NULL;
} else if (e - p > 0) {
zend_long port;
char *end;
memcpy(port_buf, p, (e - p));
port_buf[e - p] = '\0';
port = ZEND_STRTOL(port_buf, NULL, 10);
if (port > 0 && port <= 65535) {
port = ZEND_STRTOL(port_buf, &end, 10);
if (port >= 0 && port <= 65535 && end != port_buf) {
ret->port = (unsigned short)port;
} else {
php_url_free(ret);
Expand Down