mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
BUG: Labels that are FQDN can cause panics (#1040)
This commit is contained in:
@ -281,13 +281,29 @@ func ValidateAndNormalizeConfig(config *models.DNSConfig) (errs []error) {
|
|||||||
if rec.TTL == 0 {
|
if rec.TTL == 0 {
|
||||||
rec.TTL = models.DefaultTTL
|
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
|
// in-addr.arpa magic
|
||||||
if strings.HasSuffix(domain.Name, ".in-addr.arpa") || strings.HasSuffix(domain.Name, ".ip6.arpa") {
|
if strings.HasSuffix(domain.Name, ".in-addr.arpa") || strings.HasSuffix(domain.Name, ".ip6.arpa") {
|
||||||
label := rec.GetLabel()
|
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)
|
rec.SetLabel(label[0:(len(label)-len("."+domain.Name))], domain.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the unmodified inputs:
|
// Validate the unmodified inputs:
|
||||||
if err := validateRecordTypes(rec, domain.Name, pTypes); err != nil {
|
if err := validateRecordTypes(rec, domain.Name, pTypes); err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
|
Reference in New Issue
Block a user