]> Cypherpunks repositories - gostls13.git/commitdiff
net: clarify the length limit for service name
authorMikio Hara <mikioh.mikioh@gmail.com>
Wed, 14 Dec 2016 21:19:49 +0000 (06:19 +0900)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 6 Jul 2017 14:02:46 +0000 (14:02 +0000)
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>
src/net/lookup.go

index c05731ffb3d52148995fb18df6c66cd22cba870d..c9f327050afad8a7c6323d63985b5c3fd18d18f5 100644 (file)
@@ -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) {