mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Merge branch 'PHP-7.1'
* PHP-7.1: Detect invalid port in xp_socket parse ip address
This commit is contained in:
commit
2ba2b768cc
37
ext/standard/tests/streams/parseip-001.phpt
Normal file
37
ext/standard/tests/streams/parseip-001.phpt
Normal file
@ -0,0 +1,37 @@
|
||||
--TEST--
|
||||
Use of double-port in fsockopen()
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$try = [
|
||||
'127.0.0.1:80',
|
||||
'tcp://127.0.0.1:80',
|
||||
'[::1]:80',
|
||||
'tcp://[::1]:80',
|
||||
'localhost:80',
|
||||
'tcp://localhost:80',
|
||||
];
|
||||
|
||||
foreach ($try as $addr) {
|
||||
echo "== $addr ==\n";
|
||||
var_dump(@fsockopen($addr, 81, $errno, $errstr), $errstr);
|
||||
}
|
||||
--EXPECTF--
|
||||
== 127.0.0.1:80 ==
|
||||
bool(false)
|
||||
string(41) "Failed to parse address "127.0.0.1:80:81""
|
||||
== tcp://127.0.0.1:80 ==
|
||||
bool(false)
|
||||
string(41) "Failed to parse address "127.0.0.1:80:81""
|
||||
== [::1]:80 ==
|
||||
bool(false)
|
||||
string(37) "Failed to parse address "[::1]:80:81""
|
||||
== tcp://[::1]:80 ==
|
||||
bool(false)
|
||||
string(37) "Failed to parse address "[::1]:80:81""
|
||||
== localhost:80 ==
|
||||
bool(false)
|
||||
string(41) "Failed to parse address "localhost:80:81""
|
||||
== tcp://localhost:80 ==
|
||||
bool(false)
|
||||
string(41) "Failed to parse address "localhost:80:81""
|
@ -571,37 +571,44 @@ static inline char *parse_ip_address_ex(const char *str, size_t str_len, int *po
|
||||
char *host = NULL;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
char *p;
|
||||
|
||||
if (*(str) == '[' && str_len > 1) {
|
||||
/* IPV6 notation to specify raw address with port (i.e. [fe80::1]:80) */
|
||||
p = memchr(str + 1, ']', str_len - 2);
|
||||
char *p = memchr(str + 1, ']', str_len - 2), *e = NULL;
|
||||
if (!p || *(p + 1) != ':') {
|
||||
if (get_err) {
|
||||
*err = strpprintf(0, "Failed to parse IPv6 address \"%s\"", str);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
*portno = atoi(p + 2);
|
||||
*portno = strtol(p + 2, &e, 10);
|
||||
if (e && *e) {
|
||||
if (get_err) {
|
||||
*err = strpprintf(0, "Failed to parse address \"%s\"", str);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return estrndup(str + 1, p - str - 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (str_len) {
|
||||
colon = memchr(str, ':', str_len - 1);
|
||||
} else {
|
||||
colon = NULL;
|
||||
}
|
||||
|
||||
if (colon) {
|
||||
*portno = atoi(colon + 1);
|
||||
host = estrndup(str, colon - str);
|
||||
} else {
|
||||
if (get_err) {
|
||||
*err = strpprintf(0, "Failed to parse address \"%s\"", str);
|
||||
char *e = NULL;
|
||||
*portno = strtol(colon + 1, &e, 10);
|
||||
if (!e || !*e) {
|
||||
return estrndup(str, colon - str);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return host;
|
||||
if (get_err) {
|
||||
*err = strpprintf(0, "Failed to parse address \"%s\"", str);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline char *parse_ip_address(php_stream_xport_param *xparam, int *portno)
|
||||
|
Loading…
Reference in New Issue
Block a user