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)",
Action: func(ctx *cli.Context) error {
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)
@ -74,7 +74,7 @@ var _ = cmd(catUtils, func() *cli.Command {
Usage: "Do a small operation to verify credentials (stand-alone)",
Action: func(ctx *cli.Context) error {
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)

View file

@ -138,7 +138,7 @@ func exit(err error) error {
if err == nil {
return nil
}
return cli.NewExitError(err, 1)
return cli.Exit(err, 1)
}
// 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:
err = rc.SetTargetTXTs(v.Txt)
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 {
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))
}
if strings.HasSuffix(fqdn, ".") {
// Trim off a trailing dot.
fqdn = fqdn[:len(fqdn)-1]
}
// Trim off a trailing dot.
fqdn = strings.TrimSuffix(fqdn, ".")
fqdn = strings.ToLower(fqdn)
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 (!ignoreNameException(dr)) && (!apexException(dr)) {
return nil, nil, nil, nil, fmt.Errorf("trying to update/add IGNORE_NAMEd record: %s %s", dr.GetLabel(), dr.Type)
} else {
//fmt.Printf("********** DEBUG: desired EXCEPTION\n")
//} else {
// fmt.Printf("********** DEBUG: desired EXCEPTION\n")
}
} 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)

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(checkTarget(target))
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":
check(checkTarget(target))
@ -505,7 +505,7 @@ func parseDomainSpec(s string) (domain, tag string) {
func checkAutoDNSSEC(dc *models.DomainConfig) (errs []error) {
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
}

View file

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

View file

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