]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix crash on missing port
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 2 Sep 2011 09:29:20 +0000 (21:29 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 2 Sep 2011 09:29:20 +0000 (21:29 +1200)
src/client_side_request.cc

index 9a86d469a7879e7372a395cc49a10fc23b727b0a..08a38ad3a574c28ffc99194a4e238886c43e9dfe 100644 (file)
@@ -581,7 +581,6 @@ ClientRequestContext::hostHeaderVerify()
 {
     // Require a Host: header.
     const char *host = http->request->header.getStr(HDR_HOST);
-    char *hostB = NULL;
 
     if (!host) {
         // TODO: dump out the HTTP/1.1 error about missing host header.
@@ -601,27 +600,24 @@ ClientRequestContext::hostHeaderVerify()
 
     // Locate if there is a port attached, strip ready for IP lookup
     char *portStr = NULL;
-    uint16_t port = 0;
+    char *hostB = xstrdup(host);
+    host = hostB;
     if (host[0] == '[') {
         // IPv6 literal.
-        hostB = xstrdup(host);
         portStr = strchr(hostB, ']');
-        if (portStr) {
-            if (*(++portStr) == ':') {
-                *portStr = '\0';
-                port = xatoi(++portStr);
-            } else {
-                portStr=NULL; // no port to check.
-            }
+        if (portStr && *(++portStr) != ':') {
+            portStr = NULL;
         }
-        host = hostB; // point host at the local version for lookup
-    } else if (strrchr(host, ':') != NULL) {
+    } else {
         // Domain or IPv4 literal with port
-        hostB = xstrdup(host);
         portStr = strrchr(hostB, ':');
-        *portStr = '\0';
-        port = xatoi(++portStr);
-        host = hostB; // point host at the local version for lookup
+    }
+
+    uint16_t port = 0;
+    if (portStr) {
+        *portStr = '\0'; // strip the ':'
+        if (*(++portStr) != '\0')
+            port = xatoi(portStr);
     }
 
     debugs(85, 3, HERE << "validate host=" << host << ", port=" << port << ", portStr=" << (portStr?portStr:"NULL"));