Commit 5a88e54f authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net: make LookupPort with empty service mean 0

Fixes #13610

Change-Id: I9c8f924dc1ad515a9697291e981ece34fdbec8b7
Reviewed-on: https://go-review.googlesource.com/17755
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 2190750c
......@@ -123,6 +123,11 @@ 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 service == "" {
// Lock in the legacy behavior that an empty string
// means port 0. See Issue 13610.
return 0, nil
}
port, _, ok := dtoi(service, 0)
if !ok && port != big && port != -big {
port, err = lookupPort(network, service)
......
......@@ -591,6 +591,12 @@ var lookupPortTests = []struct {
{"tcp", "65536", 0, false},
{"udp", "-1", 0, false},
{"udp", "65536", 0, false},
// Issue 13610: LookupPort("tcp", "")
{"tcp", "", 0, true},
{"tcp6", "", 0, true},
{"tcp4", "", 0, true},
{"udp", "", 0, true},
}
func TestLookupPort(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment