]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Better handling of strange port values in Host:
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 13 Jul 2013 12:19:45 +0000 (00:19 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 13 Jul 2013 12:19:45 +0000 (00:19 +1200)
We can do better than just producing errors about invalid port details
and treatign it as port-0.
We can instead undo the port separation and pass it through as part of
the host name to be verified with the default port number properly
assumed.

src/client_side_request.cc

index 092aa39fe761c748523fb2838edc3496b28b2dd5..7045cfbc7d00df049f4e6ea8a463da403b787f63 100644 (file)
@@ -633,8 +633,16 @@ ClientRequestContext::hostHeaderVerify()
     uint16_t port = 0;
     if (portStr) {
         *portStr = '\0'; // strip the ':'
-        if (*(++portStr) != '\0')
-            port = xatoi(portStr);
+        if (*(++portStr) != '\0') {
+            char *end = NULL;
+            int64_t ret = strtoll(portStr, &end, 10);
+            if (end == portStr || *end != '\0' || ret < 1 || ret > 0xFFFF) {
+                // invalid port details. Replace the ':'
+                *(--portStr) = ':';
+                portStr = NULL;
+            } else
+                port = (ret & 0xFFFF);
+        }
     }
 
     debugs(85, 3, HERE << "validate host=" << host << ", port=" << port << ", portStr=" << (portStr?portStr:"NULL"));