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.
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"));