Skip to content
forked from php/php-src

Commit c0f8cc1

Browse files
committed
Merge branch 'PHP-7.4' into master
* PHP-7.4: Fix #80114: parse_url does not accept URLs with port 0
2 parents 93745a2 + 105132b commit c0f8cc1

12 files changed

+33
-4
lines changed

ext/standard/tests/url/parse_url_basic_001.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,15 @@ echo "Done";
873873
string(3) "%:x"
874874
}
875875

876+
--> https://example.com:0/: array(3) {
877+
["scheme"]=>
878+
string(5) "https"
879+
["host"]=>
880+
string(11) "example.com"
881+
["path"]=>
882+
string(1) "/"
883+
}
884+
876885
--> http:///blah.com: bool(false)
877886

878887
--> 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
@@ -107,6 +107,7 @@ echo "Done";
107107
--> / : NULL
108108
--> /rest/Users?filter={"id":"123"} : NULL
109109
--> %:x : NULL
110+
--> https://example.com:0/ : string(5) "https"
110111
--> http:///blah.com : bool(false)
111112
--> http://:80 : bool(false)
112113
--> 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
@@ -106,6 +106,7 @@ echo "Done";
106106
--> / : NULL
107107
--> /rest/Users?filter={"id":"123"} : NULL
108108
--> %:x : NULL
109+
--> https://example.com:0/ : string(11) "example.com"
109110
--> http:///blah.com : bool(false)
110111
--> http://:80 : bool(false)
111112
--> 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
@@ -106,6 +106,7 @@ echo "Done";
106106
--> / : NULL
107107
--> /rest/Users?filter={"id":"123"} : NULL
108108
--> %:x : NULL
109+
--> https://example.com:0/ : NULL
109110
--> http:///blah.com : bool(false)
110111
--> http://:80 : bool(false)
111112
--> 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
@@ -106,6 +106,7 @@ echo "Done";
106106
--> / : NULL
107107
--> /rest/Users?filter={"id":"123"} : NULL
108108
--> %:x : NULL
109+
--> https://example.com:0/ : NULL
109110
--> http:///blah.com : bool(false)
110111
--> http://:80 : bool(false)
111112
--> 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
@@ -106,6 +106,7 @@ echo "Done";
106106
--> / : NULL
107107
--> /rest/Users?filter={"id":"123"} : NULL
108108
--> %:x : NULL
109+
--> https://example.com:0/ : NULL
109110
--> http:///blah.com : bool(false)
110111
--> http://:80 : bool(false)
111112
--> 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
@@ -106,6 +106,7 @@ echo "Done";
106106
--> / : string(1) "/"
107107
--> /rest/Users?filter={"id":"123"} : string(11) "/rest/Users"
108108
--> %:x : string(3) "%:x"
109+
--> https://example.com:0/ : string(1) "/"
109110
--> http:///blah.com : bool(false)
110111
--> http://:80 : bool(false)
111112
--> 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
@@ -106,6 +106,7 @@ echo "Done";
106106
--> / : NULL
107107
--> /rest/Users?filter={"id":"123"} : string(19) "filter={"id":"123"}"
108108
--> %:x : NULL
109+
--> https://example.com:0/ : NULL
109110
--> http:///blah.com : bool(false)
110111
--> http://:80 : bool(false)
111112
--> 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
@@ -106,6 +106,7 @@ echo "Done";
106106
--> / : NULL
107107
--> /rest/Users?filter={"id":"123"} : NULL
108108
--> %:x : NULL
109+
--> https://example.com:0/ : NULL
109110
--> http:///blah.com : bool(false)
110111
--> http://:80 : bool(false)
111112
--> 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
@@ -881,6 +881,15 @@ echo "Done";
881881
string(3) "%:x"
882882
}
883883

884+
--> https://example.com:0/: array(3) {
885+
["scheme"]=>
886+
string(5) "https"
887+
["host"]=>
888+
string(11) "example.com"
889+
["path"]=>
890+
string(1) "/"
891+
}
892+
884893
--> http:///blah.com: bool(false)
885894

886895
--> 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
@@ -183,10 +183,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
183183

184184
if (pp - p > 0 && pp - p < 6 && (pp == ue || *pp == '/')) {
185185
zend_long port;
186+
char *end;
186187
memcpy(port_buf, p, (pp - p));
187188
port_buf[pp - p] = '\0';
188-
port = ZEND_STRTOL(port_buf, NULL, 10);
189-
if (port > 0 && port <= 65535) {
189+
port = ZEND_STRTOL(port_buf, &end, 10);
190+
if (port >= 0 && port <= 65535 && end != port_buf) {
190191
ret->port = (unsigned short) port;
191192
if (s + 1 < ue && *s == '/' && *(s + 1) == '/') { /* relative-scheme URL */
192193
s += 2;
@@ -247,10 +248,11 @@ PHPAPI php_url *php_url_parse_ex(char const *str, size_t length)
247248
return NULL;
248249
} else if (e - p > 0) {
249250
zend_long port;
251+
char *end;
250252
memcpy(port_buf, p, (e - p));
251253
port_buf[e - p] = '\0';
252-
port = ZEND_STRTOL(port_buf, NULL, 10);
253-
if (port > 0 && port <= 65535) {
254+
port = ZEND_STRTOL(port_buf, &end, 10);
255+
if (port >= 0 && port <= 65535 && end != port_buf) {
254256
ret->port = (unsigned short)port;
255257
} else {
256258
php_url_free(ret);

0 commit comments

Comments
 (0)