summaryrefslogtreecommitdiff
path: root/main/streams
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2017-03-07 12:11:22 -0800
committerSara Golemon <pollita@php.net>2017-03-07 12:11:22 -0800
commit1a19b97ac3e824138a5fde4b86638b6d69f64a78 (patch)
tree976242cab0dbed3b7de1b2c8eff103c48b47f244 /main/streams
parentb8f75e75f65c26f0b8d606a3ddac96015db79088 (diff)
parentbab0b99f376dac9170ac81382a5ed526938d595a (diff)
downloadphp-git-1a19b97ac3e824138a5fde4b86638b6d69f64a78.tar.gz
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Detect invalid port in xp_socket parse ip address
Diffstat (limited to 'main/streams')
-rw-r--r--main/streams/xp_socket.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index e496a2d7fd..83b8fc7e30 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -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)