Skip to content

Commit bb3be40

Browse files
cixtorbradfitz
authored andcommitted
net: clarify the length limit for service name
Change-Id: If5495f66d175bdacebd599abf1e064d2343669c2 Reviewed-on: https://go-review.googlesource.com/34430 Run-TryBot: Mikio Hara <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent a5179bd commit bb3be40

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/net/lookup.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var protocols = map[string]int{
2828
// services contains minimal mappings between services names and port
2929
// numbers for platforms that don't have a complete list of port numbers
3030
// (some Solaris distros, nacl, etc).
31+
//
32+
// See https://www.iana.org/assignments/service-names-port-numbers
33+
//
3134
// On Unix, this map is augmented by readServices via goLookupPort.
3235
var services = map[string]map[string]int{
3336
"udp": {
@@ -63,7 +66,12 @@ func lookupProtocolMap(name string) (int, error) {
6366
return proto, nil
6467
}
6568

66-
const maxServiceLength = len("mobility-header") + 10 // with room to grow
69+
// maxPortBufSize is the longest reasonable name of a service
70+
// (non-numeric port).
71+
// Currently the longest known IANA-unregistered name is
72+
// "mobility-header", so we use that length, plus some slop in case
73+
// something longer is added in the future.
74+
const maxPortBufSize = len("mobility-header") + 10
6775

6876
func lookupPortMap(network, service string) (port int, error error) {
6977
switch network {
@@ -74,7 +82,7 @@ func lookupPortMap(network, service string) (port int, error error) {
7482
}
7583

7684
if m, ok := services[network]; ok {
77-
var lowerService [maxServiceLength]byte
85+
var lowerService [maxPortBufSize]byte
7886
n := copy(lowerService[:], service)
7987
lowerASCIIBytes(lowerService[:n])
8088
if port, ok := m[string(lowerService[:n])]; ok && n == len(service) {

0 commit comments

Comments
 (0)