mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-09-06 05:04:29 +08:00
Fix CodeQL issues (#1173)
This commit is contained in:
parent
311a6d74ce
commit
6d64fc8cac
4 changed files with 37 additions and 21 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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], "\""))
|
||||
|
|
Loading…
Add table
Reference in a new issue