Commit bb3be403 authored by Mikio Hara's avatar Mikio Hara Committed by Brad Fitzpatrick

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent a5179bd0
...@@ -28,6 +28,9 @@ var protocols = map[string]int{ ...@@ -28,6 +28,9 @@ var protocols = map[string]int{
// services contains minimal mappings between services names and port // services contains minimal mappings between services names and port
// numbers for platforms that don't have a complete list of port numbers // numbers for platforms that don't have a complete list of port numbers
// (some Solaris distros, nacl, etc). // (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. // On Unix, this map is augmented by readServices via goLookupPort.
var services = map[string]map[string]int{ var services = map[string]map[string]int{
"udp": { "udp": {
...@@ -63,7 +66,12 @@ func lookupProtocolMap(name string) (int, error) { ...@@ -63,7 +66,12 @@ func lookupProtocolMap(name string) (int, error) {
return proto, nil 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) { func lookupPortMap(network, service string) (port int, error error) {
switch network { switch network {
...@@ -74,7 +82,7 @@ func lookupPortMap(network, service string) (port int, error error) { ...@@ -74,7 +82,7 @@ func lookupPortMap(network, service string) (port int, error error) {
} }
if m, ok := services[network]; ok { if m, ok := services[network]; ok {
var lowerService [maxServiceLength]byte var lowerService [maxPortBufSize]byte
n := copy(lowerService[:], service) n := copy(lowerService[:], service)
lowerASCIIBytes(lowerService[:n]) lowerASCIIBytes(lowerService[:n])
if port, ok := m[string(lowerService[:n])]; ok && n == len(service) { if port, ok := m[string(lowerService[:n])]; ok && n == len(service) {
......
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