moriyoshi                                Wed, 20 Jul 2011 04:34:01 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=313464

Log:
- Fixed bug #55073 (PHP-CLI-webserver does not listen on ipv6 interfaces), 
letting getaddrinfo(3) validate IPv6 addresses.

Bug: https://bugs.php.net/55073 (Assigned) PHP-CLI-webserver does not listen on 
ipv6 interfaces
      
Changed paths:
    U   php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
    U   php/php-src/trunk/sapi/cli/php_cli_server.c

Modified: php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-07-20 
03:11:53 UTC (rev 313463)
+++ php/php-src/branches/PHP_5_4/sapi/cli/php_cli_server.c      2011-07-20 
04:34:01 UTC (rev 313464)
@@ -1806,19 +1806,35 @@
        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 @@
        }
        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);

Modified: php/php-src/trunk/sapi/cli/php_cli_server.c
===================================================================
--- php/php-src/trunk/sapi/cli/php_cli_server.c 2011-07-20 03:11:53 UTC (rev 
313463)
+++ php/php-src/trunk/sapi/cli/php_cli_server.c 2011-07-20 04:34:01 UTC (rev 
313464)
@@ -1806,19 +1806,35 @@
        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 @@
        }
        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);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to