Skip to content
forked from php/php-src

Commit 105132b

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #80114: parse_url does not accept URLs with port 0
2 parents 9d1c7f8 + 81b2f3e commit 105132b

13 files changed

+36
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ PHP NEWS
1515
- PCRE:
1616
. Updated to PCRE 10.35. (cmb)
1717

18+
- Standard:
19+
. Fixed bug #80114 (parse_url does not accept URLs with port 0). (cmb, twosee)
20+
1821
01 Oct 2020, PHP 7.4.11
1922

2023
- Core:

ext/standard/tests/url/parse_url_basic_001.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,15 @@ echo "Done";
859859
string(3) "%:x"
860860
}
861861

862+
--> https://example.com:0/: array(3) {
863+
["scheme"]=>
864+
string(5) "https"
865+
["host"]=>
866+
string(11) "example.com"
867+
["path"]=>
868+
string(1) "/"
869+
}
870+
862871
--> http:///blah.com: bool(false)
863872

864873
--> http://:80: bool(false)

ext/standard/tests/url/parse_url_basic_002.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ echo "Done";
113113
--> / : NULL
114114
--> /rest/Users?filter={"id":"123"} : NULL
115115
--> %:x : NULL
116+
--> https://example.com:0/ : string(5) "https"
116117
--> http:///blah.com : bool(false)
117118
--> http://:80 : bool(false)
118119
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_basic_003.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ echo "Done";
112112
--> / : NULL
113113
--> /rest/Users?filter={"id":"123"} : NULL
114114
--> %:x : NULL
115+
--> https://example.com:0/ : string(11) "example.com"
115116
--> http:///blah.com : bool(false)
116117
--> http://:80 : bool(false)
117118
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_basic_004.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ echo "Done";
112112
--> / : NULL
113113
--> /rest/Users?filter={"id":"123"} : NULL
114114
--> %:x : NULL
115+
--> https://example.com:0/ : NULL
115116
--> http:///blah.com : bool(false)
116117
--> http://:80 : bool(false)
117118
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_basic_005.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ echo "Done";
112112
--> / : NULL
113113
--> /rest/Users?filter={"id":"123"} : NULL
114114
--> %:x : NULL
115+
--> https://example.com:0/ : NULL
115116
--> http:///blah.com : bool(false)
116117
--> http://:80 : bool(false)
117118
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_basic_006.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ echo "Done";
112112
--> / : NULL
113113
--> /rest/Users?filter={"id":"123"} : NULL
114114
--> %:x : NULL
115+
--> https://example.com:0/ : NULL
115116
--> http:///blah.com : bool(false)
116117
--> http://:80 : bool(false)
117118
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_basic_007.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ echo "Done";
112112
--> / : string(1) "/"
113113
--> /rest/Users?filter={"id":"123"} : string(11) "/rest/Users"
114114
--> %:x : string(3) "%:x"
115+
--> https://example.com:0/ : string(1) "/"
115116
--> http:///blah.com : bool(false)
116117
--> http://:80 : bool(false)
117118
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_basic_008.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ echo "Done";
112112
--> / : NULL
113113
--> /rest/Users?filter={"id":"123"} : string(19) "filter={"id":"123"}"
114114
--> %:x : NULL
115+
--> https://example.com:0/ : NULL
115116
--> http:///blah.com : bool(false)
116117
--> http://:80 : bool(false)
117118
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_basic_009.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ echo "Done";
112112
--> / : NULL
113113
--> /rest/Users?filter={"id":"123"} : NULL
114114
--> %:x : NULL
115+
--> https://example.com:0/ : NULL
115116
--> http:///blah.com : bool(false)
116117
--> http://:80 : bool(false)
117118
--> http://user@:80 : bool(false)

ext/standard/tests/url/parse_url_unterminated.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,15 @@ echo "Done";
861861
string(3) "%:x"
862862
}
863863

864+
--> https://example.com:0/: array(3) {
865+
["scheme"]=>
866+
string(5) "https"
867+
["host"]=>
868+
string(11) "example.com"
869+
["path"]=>
870+
string(1) "/"
871+
}
872+
864873
--> http:///blah.com: bool(false)
865874

866875
--> http://:80: bool(false)

ext/standard/tests/url/urls.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ $urls = array(
9292
'/',
9393
'/rest/Users?filter={"id":"123"}',
9494
'%:x',
95+
'https://example.com:0/',
9596

9697
// Severely malformed URLs that do not parse:
9798
'http:///blah.com',

ext/standard/url.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
190190

191191
if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) {
192192
zend_long port;
193+
char *end;
193194
memcpy(port_buf, p, (pp - p));
194195
port_buf[pp - p] = '\0';
195-
port = ZEND_STRTOL(port_buf, NULL, 10);
196-
if (port > 0 && port <= 65535) {
196+
port = ZEND_STRTOL(port_buf, &end, 10);
197+
if (port >= 0 && port <= 65535 && end != port_buf) {
197198
ret->port = (unsigned short) port;
198199
if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
199200
s += 2;
@@ -254,10 +255,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
254255
return NULL;
255256
} else if (e - p > 0) {
256257
zend_long port;
258+
char *end;
257259
memcpy(port_buf, p, (e - p));
258260
port_buf[e - p] = '\0';
259-
port = ZEND_STRTOL(port_buf, NULL, 10);
260-
if (port > 0 && port <= 65535) {
261+
port = ZEND_STRTOL(port_buf, &end, 10);
262+
if (port >= 0 && port <= 65535 && end != port_buf) {
261263
ret->port = (unsigned short)port;
262264
} else {
263265
php_url_free(ret);

0 commit comments

Comments
 (0)