]> granicus.if.org Git - php/commitdiff
Fix php cli (-S option) inconsistent port parsing
authornil0x42 <nil0x42@users.noreply.github.com>
Fri, 11 Jul 2014 17:48:03 +0000 (19:48 +0200)
committerStanislav Malyshev <stas@php.net>
Mon, 1 Dec 2014 06:42:12 +0000 (22:42 -0800)
Add port range verification of listening port with -S option for the php cli.
This fixes inconsistent listening port due to unverified cast from long to short
with htons(3).

sapi/cli/php_cli_server.c

index f333addafdc8121383a55ac0e531f97dc62a2712..f7f1c2bae0dd2ba571928a428d1ccb11e0231009 100644 (file)
@@ -2256,7 +2256,7 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c
                        *p++ = '\0';
                        if (*p == ':') {
                                port = strtol(p + 1, &p, 10);
-                               if (port <= 0) {
+                               if (port <= 0 || port > 65535) {
                                        p = NULL;
                                }
                        } else if (*p != '\0') {
@@ -2272,7 +2272,7 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c
                if (p) {
                        *p++ = '\0';
                        port = strtol(p, &p, 10);
-                       if (port <= 0) {
+                       if (port <= 0 || port > 65535) {
                                p = NULL;
                        }
                }