From 972bef1194c44091dfe694c1abbf77fc39b70c26 Mon Sep 17 00:00:00 2001 From: Adrien Raffin-Caboisse Date: Wed, 23 Feb 2022 14:21:46 +0100 Subject: [PATCH] feat: add length error if hostname too long --- machine.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/machine.go b/machine.go index 25edd1d1..4536ef3f 100644 --- a/machine.go +++ b/machine.go @@ -25,6 +25,11 @@ const ( errMachineAlreadyRegistered = Error("machine already registered") errMachineRouteIsNotAvailable = Error("route is not available on machine") errMachineAddressesInvalid = Error("failed to parse machine addresses") + errHostnameTooLong = Error("Hostname too long") +) + +const ( + maxHostnameLength = 255 ) // Machine is a Headscale client. @@ -727,6 +732,13 @@ func (machine Machine) toNode( machine.Namespace.Name, baseDomain, ) + if len(hostname) > maxHostnameLength { + return nil, fmt.Errorf( + "hostname %q is too long it cannot except 255 ASCII chars: %w", + hostname, + errHostnameTooLong, + ) + } } else { hostname = machine.Name }