1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Security: Fix many staticcheck warnings

This commit is contained in:
Tom Limoncelli
2021-12-14 09:47:32 -05:00
parent e3cd40a1a8
commit 7ae27aa0b9
8 changed files with 16 additions and 15 deletions

View File

@@ -21,7 +21,7 @@ var _ = cmd(catUtils, func() *cli.Command {
Usage: "gets a zone from a provider (stand-alone)", Usage: "gets a zone from a provider (stand-alone)",
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
if ctx.NArg() < 3 { if ctx.NArg() < 3 {
return cli.NewExitError("Arguments should be: credskey providername zone(s) (Ex: r53 ROUTE53 example.com)", 1) return cli.Exit("Arguments should be: credskey providername zone(s) (Ex: r53 ROUTE53 example.com)", 1)
} }
args.CredName = ctx.Args().Get(0) args.CredName = ctx.Args().Get(0)
@@ -74,7 +74,7 @@ var _ = cmd(catUtils, func() *cli.Command {
Usage: "Do a small operation to verify credentials (stand-alone)", Usage: "Do a small operation to verify credentials (stand-alone)",
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
if ctx.NArg() != 2 { if ctx.NArg() != 2 {
return cli.NewExitError("Arguments should be: credskey providername (Ex: r53 ROUTE53)", 1) return cli.Exit("Arguments should be: credskey providername (Ex: r53 ROUTE53)", 1)
} }
args.CredName = ctx.Args().Get(0) args.CredName = ctx.Args().Get(0)

View File

@@ -138,7 +138,7 @@ func exit(err error) error {
if err == nil { if err == nil {
return nil return nil
} }
return cli.NewExitError(err, 1) return cli.Exit(err, 1)
} }
// stringSliceToMap converts cli.StringSlice to map[string]string for further processing // stringSliceToMap converts cli.StringSlice to map[string]string for further processing

View File

@@ -95,7 +95,7 @@ func RRtoRC(rr dns.RR, origin string) (RecordConfig, error) {
case *dns.TXT: case *dns.TXT:
err = rc.SetTargetTXTs(v.Txt) err = rc.SetTargetTXTs(v.Txt)
default: default:
return *rc, fmt.Errorf("rrToRecord: Unimplemented zone record type=%s (%v)\n", rc.Type, rr) return *rc, fmt.Errorf("rrToRecord: Unimplemented zone record type=%s (%v)", rc.Type, rr)
} }
if err != nil { if err != nil {
return *rc, fmt.Errorf("unparsable record received: %w", err) return *rc, fmt.Errorf("unparsable record received: %w", err)

View File

@@ -264,10 +264,8 @@ func (rc *RecordConfig) SetLabelFromFQDN(fqdn, origin string) {
panic(fmt.Errorf("fqdn (%s) is not supposed to end with double dots", origin)) panic(fmt.Errorf("fqdn (%s) is not supposed to end with double dots", origin))
} }
if strings.HasSuffix(fqdn, ".") { // Trim off a trailing dot.
// Trim off a trailing dot. fqdn = strings.TrimSuffix(fqdn, ".")
fqdn = fqdn[:len(fqdn)-1]
}
fqdn = strings.ToLower(fqdn) fqdn = strings.ToLower(fqdn)
origin = strings.ToLower(origin) origin = strings.ToLower(origin)

View File

@@ -141,8 +141,8 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
//if !apexException(dr) || !ignoreNameException(dr) { //if !apexException(dr) || !ignoreNameException(dr) {
if (!ignoreNameException(dr)) && (!apexException(dr)) { if (!ignoreNameException(dr)) && (!apexException(dr)) {
return nil, nil, nil, nil, fmt.Errorf("trying to update/add IGNORE_NAMEd record: %s %s", dr.GetLabel(), dr.Type) return nil, nil, nil, nil, fmt.Errorf("trying to update/add IGNORE_NAMEd record: %s %s", dr.GetLabel(), dr.Type)
} else { //} else {
//fmt.Printf("********** DEBUG: desired EXCEPTION\n") // fmt.Printf("********** DEBUG: desired EXCEPTION\n")
} }
} else if d.matchIgnoredTarget(dr.GetTargetField(), dr.Type) { } else if d.matchIgnoredTarget(dr.GetTargetField(), dr.Type) {
return nil, nil, nil, nil, fmt.Errorf("trying to update/add IGNORE_TARGETd record: %s %s", dr.GetLabel(), dr.Type) return nil, nil, nil, nil, fmt.Errorf("trying to update/add IGNORE_TARGETd record: %s %s", dr.GetLabel(), dr.Type)

View File

@@ -189,7 +189,7 @@ func checkTargets(rec *models.RecordConfig, domain string) (errs []error) {
check(checkSoa(rec.SoaExpire, rec.SoaMinttl, rec.SoaRefresh, rec.SoaRetry, rec.SoaSerial, rec.SoaMbox)) check(checkSoa(rec.SoaExpire, rec.SoaMinttl, rec.SoaRefresh, rec.SoaRetry, rec.SoaSerial, rec.SoaMbox))
check(checkTarget(target)) check(checkTarget(target))
if label != "@" { if label != "@" {
check(fmt.Errorf("SOA record is only valid for bare domain.")) check(fmt.Errorf("SOA record is only valid for bare domain"))
} }
case "SRV": case "SRV":
check(checkTarget(target)) check(checkTarget(target))
@@ -505,7 +505,7 @@ func parseDomainSpec(s string) (domain, tag string) {
func checkAutoDNSSEC(dc *models.DomainConfig) (errs []error) { func checkAutoDNSSEC(dc *models.DomainConfig) (errs []error) {
if dc.AutoDNSSEC != "" && dc.AutoDNSSEC != "on" && dc.AutoDNSSEC != "off" { if dc.AutoDNSSEC != "" && dc.AutoDNSSEC != "on" && dc.AutoDNSSEC != "off" {
errs = append(errs, fmt.Errorf("Domain %q AutoDNSSEC=%q is invalid (expecting \"\", \"off\", or \"on\")", dc.Name, dc.AutoDNSSEC)) errs = append(errs, fmt.Errorf("domain %q AutoDNSSEC=%q is invalid (expecting \"\", \"off\", or \"on\")", dc.Name, dc.AutoDNSSEC))
} }
return return
} }

View File

@@ -15,7 +15,7 @@ func TxtNoBackticks(records []*models.RecordConfig) error {
if rc.HasFormatIdenticalToTXT() { if rc.HasFormatIdenticalToTXT() {
for _, txt := range rc.TxtStrings { for _, txt := range rc.TxtStrings {
if strings.Index(txt, "`") != -1 { if strings.Contains(txt, "`") {
return fmt.Errorf("txtstring contains backtick") return fmt.Errorf("txtstring contains backtick")
} }
} }
@@ -31,7 +31,7 @@ func TxtNoSingleQuotes(records []*models.RecordConfig) error {
if rc.HasFormatIdenticalToTXT() { if rc.HasFormatIdenticalToTXT() {
for _, txt := range rc.TxtStrings { for _, txt := range rc.TxtStrings {
if strings.Index(txt, "'") != -1 { if strings.Contains(txt, "'") {
return fmt.Errorf("txtstring contains single-quotes") return fmt.Errorf("txtstring contains single-quotes")
} }
} }
@@ -47,7 +47,7 @@ func TxtNoDoubleQuotes(records []*models.RecordConfig) error {
if rc.HasFormatIdenticalToTXT() { if rc.HasFormatIdenticalToTXT() {
for _, txt := range rc.TxtStrings { for _, txt := range rc.TxtStrings {
if strings.Index(txt, `"`) != -1 { if strings.Contains(txt, `"`) {
return fmt.Errorf("txtstring contains doublequotes") return fmt.Errorf("txtstring contains doublequotes")
} }
} }

View File

@@ -36,6 +36,9 @@ func LoadProviderConfigs(fname string) (map[string]map[string]string, error) {
} else { } else {
// no executable bit found nor marked as executable so read it in // no executable bit found nor marked as executable so read it in
dat, err = readCredsFile(fname) dat, err = readCredsFile(fname)
if err != nil {
return nil, err
}
} }
s := string(dat) s := string(dat)