From 6d64fc8cacb750f99fa520a76b8516374196fba5 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Thu, 24 Jun 2021 18:15:09 -0400 Subject: [PATCH] Fix CodeQL issues (#1173) --- pkg/transform/ptr.go | 2 +- providers/cloudns/cloudnsProvider.go | 24 ++++++++++++------------ providers/hedns/hednsProvider.go | 28 ++++++++++++++++++++++------ providers/netcup/types.go | 4 ++-- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/pkg/transform/ptr.go b/pkg/transform/ptr.go index 2579a6c52..d2eb8219a 100644 --- a/pkg/transform/ptr.go +++ b/pkg/transform/ptr.go @@ -88,7 +88,7 @@ func ipMatchesClasslessDomain(ip net.IP, domain string) bool { } // atob converts a to a byte value or panics. -func atob(s string) byte { +func atob(s string) uint8 { if i, err := strconv.Atoi(s); err == nil { if i < 256 { return byte(i) diff --git a/providers/cloudns/cloudnsProvider.go b/providers/cloudns/cloudnsProvider.go index 0587a54f3..fbf1443d7 100644 --- a/providers/cloudns/cloudnsProvider.go +++ b/providers/cloudns/cloudnsProvider.go @@ -201,9 +201,9 @@ func (c *cloudnsProvider) EnsureDomainExists(domain string) error { func toRc(domain string, r *domainRecord) *models.RecordConfig { ttl, _ := strconv.ParseUint(r.TTL, 10, 32) - priority, _ := strconv.ParseUint(r.Priority, 10, 32) - weight, _ := strconv.ParseUint(r.Weight, 10, 32) - port, _ := strconv.ParseUint(r.Port, 10, 32) + priority, _ := strconv.ParseUint(r.Priority, 10, 16) + weight, _ := strconv.ParseUint(r.Weight, 10, 16) + port, _ := strconv.ParseUint(r.Port, 10, 16) rc := &models.RecordConfig{ Type: r.Type, @@ -222,30 +222,30 @@ func toRc(domain string, r *domainRecord) *models.RecordConfig { case "CNAME", "MX", "NS", "SRV", "ALIAS", "PTR": rc.SetTarget(dnsutil.AddOrigin(r.Target+".", domain)) case "CAA": - caaFlag, _ := strconv.ParseUint(r.CaaFlag, 10, 32) + caaFlag, _ := strconv.ParseUint(r.CaaFlag, 10, 8) rc.CaaFlag = uint8(caaFlag) rc.CaaTag = r.CaaTag rc.SetTarget(r.CaaValue) case "TLSA": - tlsaUsage, _ := strconv.ParseUint(r.TlsaUsage, 10, 32) + tlsaUsage, _ := strconv.ParseUint(r.TlsaUsage, 10, 8) rc.TlsaUsage = uint8(tlsaUsage) - tlsaSelector, _ := strconv.ParseUint(r.TlsaSelector, 10, 32) + tlsaSelector, _ := strconv.ParseUint(r.TlsaSelector, 10, 8) rc.TlsaSelector = uint8(tlsaSelector) - tlsaMatchingType, _ := strconv.ParseUint(r.TlsaMatchingType, 10, 32) + tlsaMatchingType, _ := strconv.ParseUint(r.TlsaMatchingType, 10, 8) rc.TlsaMatchingType = uint8(tlsaMatchingType) rc.SetTarget(r.Target) case "SSHFP": - sshfpAlgorithm, _ := strconv.ParseUint(r.SshfpAlgorithm, 10, 32) + sshfpAlgorithm, _ := strconv.ParseUint(r.SshfpAlgorithm, 10, 8) rc.SshfpAlgorithm = uint8(sshfpAlgorithm) - sshfpFingerprint, _ := strconv.ParseUint(r.SshfpFingerprint, 10, 32) + sshfpFingerprint, _ := strconv.ParseUint(r.SshfpFingerprint, 10, 8) rc.SshfpFingerprint = uint8(sshfpFingerprint) rc.SetTarget(r.Target) case "DS": - dsKeyTag, _ := strconv.ParseUint(r.DsKeyTag, 10, 32) + dsKeyTag, _ := strconv.ParseUint(r.DsKeyTag, 10, 16) rc.DsKeyTag = uint16(dsKeyTag) - dsAlgorithm, _ := strconv.ParseUint(r.SshfpAlgorithm, 10, 32) // SshFpAlgorithm and DsAlgorithm both use json field "algorithm" + dsAlgorithm, _ := strconv.ParseUint(r.SshfpAlgorithm, 10, 8) // SshFpAlgorithm and DsAlgorithm both use json field "algorithm" rc.DsAlgorithm = uint8(dsAlgorithm) - dsDigestType, _ := strconv.ParseUint(r.DsDigestType, 10, 32) + dsDigestType, _ := strconv.ParseUint(r.DsDigestType, 10, 8) rc.DsDigestType = uint8(dsDigestType) rc.DsDigest = r.Target rc.SetTarget(r.Target) diff --git a/providers/hedns/hednsProvider.go b/providers/hedns/hednsProvider.go index 3a0b4548a..17607e7c8 100644 --- a/providers/hedns/hednsProvider.go +++ b/providers/hedns/hednsProvider.go @@ -295,7 +295,7 @@ func (c *hednsProvider) GetZoneRecords(domain string) (models.Records, error) { rc := &models.RecordConfig{ Type: parser.parseStringAttr(element.Find("td > .rrlabel"), "data"), - TTL: uint32(parser.parseIntElement(element.Find("td:nth-child(5)"))), + TTL: parser.parseIntElementUint32(element.Find("td:nth-child(5)")), Original: Record{ ZoneName: domain, ZoneID: domainID, @@ -308,7 +308,7 @@ func (c *hednsProvider) GetZoneRecords(domain string) (models.Records, error) { return false } - priority := parser.parseIntElement(element.Find("td:nth-child(6)")) + priority := parser.parseIntElementUint16(element.Find("td:nth-child(6)")) if parser.err != nil { err = parser.err return false @@ -731,9 +731,9 @@ func (p *elementParser) parseStringElement(element *goquery.Selection) (result s return element.Text() } -func (p *elementParser) parseIntElement(element *goquery.Selection) (result uint64) { +func (p *elementParser) parseIntElementUint16(element *goquery.Selection) uint16 { if p.err != nil { - return + return 0 } // Special case to deal with Priority @@ -741,6 +741,22 @@ func (p *elementParser) parseIntElement(element *goquery.Selection) (result uint return 0 } - result, p.err = strconv.ParseUint(element.Text(), 10, 64) - return result + var result64 uint64 + result64, p.err = strconv.ParseUint(element.Text(), 10, 16) + return uint16(result64) +} + +func (p *elementParser) parseIntElementUint32(element *goquery.Selection) uint32 { + if p.err != nil { + return 0 + } + + // Special case to deal with Priority + if element.Text() == "-" { + return 0 + } + + var result64 uint64 + result64, p.err = strconv.ParseUint(element.Text(), 10, 32) + return uint32(result64) } diff --git a/providers/netcup/types.go b/providers/netcup/types.go index 1dd477258..784645763 100644 --- a/providers/netcup/types.go +++ b/providers/netcup/types.go @@ -72,7 +72,7 @@ type responseLogin struct { } func toRecordConfig(domain string, r *record) *models.RecordConfig { - priority, _ := strconv.ParseUint(r.Priority, 10, 32) + priority, _ := strconv.ParseUint(r.Priority, 10, 16) rc := &models.RecordConfig{ Type: r.Type, @@ -101,7 +101,7 @@ func toRecordConfig(domain string, r *record) *models.RecordConfig { _ = rc.SetTarget(parts[3]) case "CAA": parts := strings.Split(r.Destination, " ") - caaFlag, _ := strconv.ParseUint(parts[0], 10, 32) + caaFlag, _ := strconv.ParseUint(parts[0], 10, 8) rc.CaaFlag = uint8(caaFlag) rc.CaaTag = parts[1] _ = rc.SetTarget(strings.Trim(parts[2], "\""))