aboutsummaryrefslogtreecommitdiff
path: root/src/net/lookup.go
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2015-07-21 12:51:01 +0900
committerMikio Hara <mikioh.mikioh@gmail.com>2015-11-01 05:28:17 +0000
commitb50b21d3e130cf19de99c2736d038b636dde75c3 (patch)
treeff8bac2a3f5b28546610e6f877fd7a2f7cd38850 /src/net/lookup.go
parent3d5163cf4348b5e697dcbf09897a62893876ac3c (diff)
downloadgo-b50b21d3e130cf19de99c2736d038b636dde75c3.tar.gz
go-b50b21d3e130cf19de99c2736d038b636dde75c3.zip
net: make Dial, Listen{,Packet} for TCP/UDP with invalid port fail
This change makes Dial, Listen and ListenPacket with invalid port fail whatever GODEBUG=netdns is. Please be informed that cgoLookupPort with an out of range literal number may return either the lower or upper bound value, 0 or 65535, with no error on some platform. Fixes #11715. Change-Id: I43f9c4fb5526d1bf50b97698e0eb39d29fd74c35 Reviewed-on: https://go-review.googlesource.com/12447 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/lookup.go')
-rw-r--r--src/net/lookup.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/net/lookup.go b/src/net/lookup.go
index 9008322dc5..6e0cf62aec 100644
--- a/src/net/lookup.go
+++ b/src/net/lookup.go
@@ -123,10 +123,17 @@ 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
+ port, _, ok := dtoi(service, 0)
+ if !ok && port != big && port != -big {
+ port, err = lookupPort(network, service)
+ if err != nil {
+ return 0, err
+ }
}
- return lookupPort(network, service)
+ 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.