1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-10-17 20:05:55 +02:00

feat: add length error if hostname too long

This commit is contained in:
Adrien Raffin-Caboisse 2022-02-23 14:21:46 +01:00
parent 4f1f235a2e
commit 972bef1194

View File

@ -25,6 +25,11 @@ const (
errMachineAlreadyRegistered = Error("machine already registered") errMachineAlreadyRegistered = Error("machine already registered")
errMachineRouteIsNotAvailable = Error("route is not available on machine") errMachineRouteIsNotAvailable = Error("route is not available on machine")
errMachineAddressesInvalid = Error("failed to parse machine addresses") errMachineAddressesInvalid = Error("failed to parse machine addresses")
errHostnameTooLong = Error("Hostname too long")
)
const (
maxHostnameLength = 255
) )
// Machine is a Headscale client. // Machine is a Headscale client.
@ -727,6 +732,13 @@ func (machine Machine) toNode(
machine.Namespace.Name, machine.Namespace.Name,
baseDomain, baseDomain,
) )
if len(hostname) > maxHostnameLength {
return nil, fmt.Errorf(
"hostname %q is too long it cannot except 255 ASCII chars: %w",
hostname,
errHostnameTooLong,
)
}
} else { } else {
hostname = machine.Name hostname = machine.Name
} }