config: bind naked ports to localhost

If only a port is given as a config value for a listener we'll
default to only binding that port to localhost.
This commit is contained in:
Matt Drollette 2018-03-17 21:49:10 -05:00 committed by Olaoluwa Osuntokun
parent ffb1b65eca
commit 87333ba829

View File

@ -1099,7 +1099,13 @@ func normalizeAddresses(addrs []string, defaultPort string) []string {
seen := map[string]struct{}{}
for _, addr := range addrs {
if _, _, err := net.SplitHostPort(addr); err != nil {
addr = net.JoinHostPort(addr, defaultPort)
// If the address is an integer, then we assume it is *only* a
// port and default to binding to that port on localhost
if _, err := strconv.Atoi(addr); err == nil {
addr = net.JoinHostPort("localhost", addr)
} else {
addr = net.JoinHostPort(addr, defaultPort)
}
}
if _, ok := seen[addr]; !ok {
result = append(result, addr)