diff options
author | Moriyoshi Koizumi <moriyoshi@php.net> | 2011-07-20 04:34:01 +0000 |
---|---|---|
committer | Moriyoshi Koizumi <moriyoshi@php.net> | 2011-07-20 04:34:01 +0000 |
commit | a07a4af30b7641f39822904d290bd736b25f0acf (patch) | |
tree | ba58bc8763f89dadbfb60e79b20871feed6073a1 /sapi/cli/php_cli_server.c | |
parent | b03817afb5c2bc8808dd402f1d9b0d1e51401da4 (diff) | |
download | php-git-a07a4af30b7641f39822904d290bd736b25f0acf.tar.gz |
- Fixed bug #55073 (PHP-CLI-webserver does not listen on ipv6 interfaces), letting getaddrinfo(3) validate IPv6 addresses.
Diffstat (limited to 'sapi/cli/php_cli_server.c')
-rw-r--r-- | sapi/cli/php_cli_server.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index bad7d51213..fe1bdb1163 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -1806,17 +1806,33 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c int port = 3000; php_socket_t server_sock = SOCK_ERR; - host = pestrdup(addr, 1); - if (!host || *host == ':' ) { - if (host) { - pefree(host, 1); + if (addr[0] == '[') { + char *p; + host = pestrdup(addr + 1, 1); + if (!host) { + return FAILURE; } - fprintf(stderr, "Invalid built-in web-server addr:port argument\n"); - return FAILURE; - } - - { - char *p = strchr(host, ':'); + p = strchr(host, ']'); + if (p) { + *p++ = '\0'; + if (*p == ':') { + port = strtol(p + 1, &p, 10); + } else if (*p != '\0') { + p = NULL; + } + } + if (!p) { + fprintf(stderr, "Invalid IPv6 address: %s\n", host); + retval = FAILURE; + goto out; + } + } else { + char *p; + host = pestrdup(addr, 1); + if (!host) { + return FAILURE; + } + p = strrchr(host, ':'); if (p) { *p++ = '\0'; port = strtol(p, &p, 10); @@ -2106,7 +2122,7 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* {{{ */ } sapi_module.phpinfo_as_text = 0; - printf("PHP Development Server is listening on %s:%d in %s ... Press Ctrl-C to quit.\n", server.host, server.port, document_root); + printf("PHP Development Server is listening on %s in %s ... Press Ctrl-C to quit.\n", server_bind_address, document_root); #if defined(HAVE_SIGNAL_H) && defined(SIGINT) signal(SIGINT, php_cli_server_sigint_handler); |