NAMESERVER() validity check fixed (#866)

This commit is contained in:
Tom Limoncelli 2020-09-20 10:41:42 -04:00 committed by GitHub
parent c44d9a43f5
commit 408e7eb0ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,7 +33,7 @@ func checkTarget(target string) error {
if target == "@" { if target == "@" {
return nil return nil
} }
if len(target) < 1 { if target == "" {
return fmt.Errorf("empty target") return fmt.Errorf("empty target")
} }
if strings.ContainsAny(target, `'" +,|!£$%&/()=?^*ç°§;:<>[]()@`) { if strings.ContainsAny(target, `'" +,|!£$%&/()=?^*ç°§;:<>[]()@`) {
@ -92,7 +92,7 @@ func checkLabel(label string, rType string, target, domain string, meta map[stri
if label == "@" { if label == "@" {
return nil return nil
} }
if len(label) < 1 { if label == "" {
return fmt.Errorf("empty %s label in %s", rType, domain) return fmt.Errorf("empty %s label in %s", rType, domain)
} }
if label[len(label)-1] == '.' { if label[len(label)-1] == '.' {
@ -272,11 +272,13 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
// Normalize Nameservers. // Normalize Nameservers.
for _, ns := range domain.Nameservers { for _, ns := range domain.Nameservers {
// NB(tlim): Like any target, NAMESERVER() is input by the user // NB(tlim): Like any target, NAMESERVER() is input by the user
// as a shortname or a FQDN+dot. It is stored as FQDN+dot. // as a shortname or a FQDN+dot.
// Normalize it like we do any target to assure it is FQDN+dot if err := checkTarget(ns.Name); err != nil {
ns.Name = dnsutil.AddOrigin(ns.Name, domain.Name+".") errs = append(errs, err)
ns.Name = strings.TrimSuffix(ns.Name, ".") }
checkTarget(ns.Name) // Unlike any other FQDN in this system, it is stored as a FQDN without the trailing dot.
n := dnsutil.AddOrigin(ns.Name, domain.Name+".")
ns.Name = strings.TrimSuffix(n, ".")
} }
// Normalize Records. // Normalize Records.