aboutsummaryrefslogtreecommitdiff
path: root/src/net/lookup.go
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2016-12-15 06:19:49 +0900
committerBrad Fitzpatrick <bradfitz@golang.org>2017-07-06 14:02:46 +0000
commitbb3be403e79731b208c41bd170a6a87642d988da (patch)
tree0d815e7b3c71b3ea578df96a1d84a2ddeb8ebfb2 /src/net/lookup.go
parenta5179bd0a56d8fae91e860f585cef143ce5ec89b (diff)
downloadgo-bb3be403e79731b208c41bd170a6a87642d988da.tar.gz
go-bb3be403e79731b208c41bd170a6a87642d988da.zip
net: clarify the length limit for service name
Change-Id: If5495f66d175bdacebd599abf1e064d2343669c2 Reviewed-on: https://go-review.googlesource.com/34430 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/lookup.go')
-rw-r--r--src/net/lookup.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/net/lookup.go b/src/net/lookup.go
index c05731ffb3..c9f327050a 100644
--- a/src/net/lookup.go
+++ b/src/net/lookup.go
@@ -28,6 +28,9 @@ var protocols = map[string]int{
// services contains minimal mappings between services names and port
// numbers for platforms that don't have a complete list of port numbers
// (some Solaris distros, nacl, etc).
+//
+// See https://www.iana.org/assignments/service-names-port-numbers
+//
// On Unix, this map is augmented by readServices via goLookupPort.
var services = map[string]map[string]int{
"udp": {
@@ -63,7 +66,12 @@ func lookupProtocolMap(name string) (int, error) {
return proto, nil
}
-const maxServiceLength = len("mobility-header") + 10 // with room to grow
+// maxPortBufSize is the longest reasonable name of a service
+// (non-numeric port).
+// Currently the longest known IANA-unregistered name is
+// "mobility-header", so we use that length, plus some slop in case
+// something longer is added in the future.
+const maxPortBufSize = len("mobility-header") + 10
func lookupPortMap(network, service string) (port int, error error) {
switch network {
@@ -74,7 +82,7 @@ func lookupPortMap(network, service string) (port int, error error) {
}
if m, ok := services[network]; ok {
- var lowerService [maxServiceLength]byte
+ var lowerService [maxPortBufSize]byte
n := copy(lowerService[:], service)
lowerASCIIBytes(lowerService[:n])
if port, ok := m[string(lowerService[:n])]; ok && n == len(service) {