BUG: Labels that are FQDN can cause panics (#1040)

This commit is contained in:
Tom Limoncelli 2021-02-05 11:58:17 -05:00 committed by GitHub
parent 236cffa9b9
commit 36289f7157
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -281,13 +281,29 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
if rec.TTL == 0 {
rec.TTL = models.DefaultTTL
}
// Canonicalize Label:
if rec.GetLabel() == (domain.Name + ".") {
// If label == ${domain}DOT, change to "@"
rec.SetLabel("@", domain.Name)
} else if lab, suf := rec.GetLabel(), "."+domain.Name+"."; strings.HasSuffix(lab, suf) {
// If label ends with DOT${domain}DOT, strip it to a short name.
rec.SetLabel(lab[:len(lab)-len(suf)], domain.Name)
}
// If label ends with dot, add to the list of errors.
if strings.HasSuffix(rec.GetLabel(), ".") {
errs = append(errs, fmt.Errorf("label %q does not match D(%q)", rec.GetLabel(), domain.Name))
return errs // Exit early.
}
// in-addr.arpa magic
if strings.HasSuffix(domain.Name, ".in-addr.arpa") || strings.HasSuffix(domain.Name, ".ip6.arpa") {
label := rec.GetLabel()
if label == domain.Name || strings.HasSuffix(label, "."+domain.Name) {
if strings.HasSuffix(label, "."+domain.Name) {
rec.SetLabel(label[0:(len(label)-len("."+domain.Name))], domain.Name)
}
}
// Validate the unmodified inputs:
if err := validateRecordTypes(rec, domain.Name, pTypes); err != nil {
errs = append(errs, err)