diff options
Diffstat (limited to 'libgo/go/net/lookup.go')
-rw-r--r-- | libgo/go/net/lookup.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/libgo/go/net/lookup.go b/libgo/go/net/lookup.go index 9008322..7aa111b 100644 --- a/libgo/go/net/lookup.go +++ b/libgo/go/net/lookup.go @@ -123,10 +123,22 @@ func lookupIPDeadline(host string, deadline time.Time) (addrs []IPAddr, err erro // LookupPort looks up the port for the given network and service. func LookupPort(network, service string) (port int, err error) { - if n, i, ok := dtoi(service, 0); ok && i == len(service) { - return n, nil + if service == "" { + // Lock in the legacy behavior that an empty string + // means port 0. See Issue 13610. + return 0, nil } - return lookupPort(network, service) + port, _, ok := dtoi(service, 0) + if !ok && port != big && port != -big { + port, err = lookupPort(network, service) + if err != nil { + return 0, err + } + } + if 0 > port || port > 65535 { + return 0, &AddrError{Err: "invalid port", Addr: service} + } + return port, nil } // LookupCNAME returns the canonical DNS host for the given name. |