util/dnsname: normalize leading dots in ToFQDN.

Fixes #1888.

Signed-off-by: David Anderson <dave@natulte.net>
This commit is contained in:
David Anderson
2021-05-10 13:04:32 -07:00
parent c0a70f3a06
commit dc32b4695c
2 changed files with 6 additions and 2 deletions

View File

@@ -24,13 +24,16 @@ func ToFQDN(s string) (FQDN, error) {
if isValidFQDN(s) {
return FQDN(s), nil
}
if len(s) == 0 {
if len(s) == 0 || s == "." {
return FQDN("."), nil
}
if s[len(s)-1] == '.' {
s = s[:len(s)-1]
}
if s[0] == '.' {
s = s[1:]
}
if len(s) > maxNameLength {
return "", fmt.Errorf("%q is too long to be a DNS name", s)
}