mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Fix CodeQL issues (#1173)
This commit is contained in:
@@ -88,7 +88,7 @@ func ipMatchesClasslessDomain(ip net.IP, domain string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// atob converts a to a byte value or panics.
|
// 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, err := strconv.Atoi(s); err == nil {
|
||||||
if i < 256 {
|
if i < 256 {
|
||||||
return byte(i)
|
return byte(i)
|
||||||
|
@@ -201,9 +201,9 @@ func (c *cloudnsProvider) EnsureDomainExists(domain string) error {
|
|||||||
func toRc(domain string, r *domainRecord) *models.RecordConfig {
|
func toRc(domain string, r *domainRecord) *models.RecordConfig {
|
||||||
|
|
||||||
ttl, _ := strconv.ParseUint(r.TTL, 10, 32)
|
ttl, _ := strconv.ParseUint(r.TTL, 10, 32)
|
||||||
priority, _ := strconv.ParseUint(r.Priority, 10, 32)
|
priority, _ := strconv.ParseUint(r.Priority, 10, 16)
|
||||||
weight, _ := strconv.ParseUint(r.Weight, 10, 32)
|
weight, _ := strconv.ParseUint(r.Weight, 10, 16)
|
||||||
port, _ := strconv.ParseUint(r.Port, 10, 32)
|
port, _ := strconv.ParseUint(r.Port, 10, 16)
|
||||||
|
|
||||||
rc := &models.RecordConfig{
|
rc := &models.RecordConfig{
|
||||||
Type: r.Type,
|
Type: r.Type,
|
||||||
@@ -222,30 +222,30 @@ func toRc(domain string, r *domainRecord) *models.RecordConfig {
|
|||||||
case "CNAME", "MX", "NS", "SRV", "ALIAS", "PTR":
|
case "CNAME", "MX", "NS", "SRV", "ALIAS", "PTR":
|
||||||
rc.SetTarget(dnsutil.AddOrigin(r.Target+".", domain))
|
rc.SetTarget(dnsutil.AddOrigin(r.Target+".", domain))
|
||||||
case "CAA":
|
case "CAA":
|
||||||
caaFlag, _ := strconv.ParseUint(r.CaaFlag, 10, 32)
|
caaFlag, _ := strconv.ParseUint(r.CaaFlag, 10, 8)
|
||||||
rc.CaaFlag = uint8(caaFlag)
|
rc.CaaFlag = uint8(caaFlag)
|
||||||
rc.CaaTag = r.CaaTag
|
rc.CaaTag = r.CaaTag
|
||||||
rc.SetTarget(r.CaaValue)
|
rc.SetTarget(r.CaaValue)
|
||||||
case "TLSA":
|
case "TLSA":
|
||||||
tlsaUsage, _ := strconv.ParseUint(r.TlsaUsage, 10, 32)
|
tlsaUsage, _ := strconv.ParseUint(r.TlsaUsage, 10, 8)
|
||||||
rc.TlsaUsage = uint8(tlsaUsage)
|
rc.TlsaUsage = uint8(tlsaUsage)
|
||||||
tlsaSelector, _ := strconv.ParseUint(r.TlsaSelector, 10, 32)
|
tlsaSelector, _ := strconv.ParseUint(r.TlsaSelector, 10, 8)
|
||||||
rc.TlsaSelector = uint8(tlsaSelector)
|
rc.TlsaSelector = uint8(tlsaSelector)
|
||||||
tlsaMatchingType, _ := strconv.ParseUint(r.TlsaMatchingType, 10, 32)
|
tlsaMatchingType, _ := strconv.ParseUint(r.TlsaMatchingType, 10, 8)
|
||||||
rc.TlsaMatchingType = uint8(tlsaMatchingType)
|
rc.TlsaMatchingType = uint8(tlsaMatchingType)
|
||||||
rc.SetTarget(r.Target)
|
rc.SetTarget(r.Target)
|
||||||
case "SSHFP":
|
case "SSHFP":
|
||||||
sshfpAlgorithm, _ := strconv.ParseUint(r.SshfpAlgorithm, 10, 32)
|
sshfpAlgorithm, _ := strconv.ParseUint(r.SshfpAlgorithm, 10, 8)
|
||||||
rc.SshfpAlgorithm = uint8(sshfpAlgorithm)
|
rc.SshfpAlgorithm = uint8(sshfpAlgorithm)
|
||||||
sshfpFingerprint, _ := strconv.ParseUint(r.SshfpFingerprint, 10, 32)
|
sshfpFingerprint, _ := strconv.ParseUint(r.SshfpFingerprint, 10, 8)
|
||||||
rc.SshfpFingerprint = uint8(sshfpFingerprint)
|
rc.SshfpFingerprint = uint8(sshfpFingerprint)
|
||||||
rc.SetTarget(r.Target)
|
rc.SetTarget(r.Target)
|
||||||
case "DS":
|
case "DS":
|
||||||
dsKeyTag, _ := strconv.ParseUint(r.DsKeyTag, 10, 32)
|
dsKeyTag, _ := strconv.ParseUint(r.DsKeyTag, 10, 16)
|
||||||
rc.DsKeyTag = uint16(dsKeyTag)
|
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)
|
rc.DsAlgorithm = uint8(dsAlgorithm)
|
||||||
dsDigestType, _ := strconv.ParseUint(r.DsDigestType, 10, 32)
|
dsDigestType, _ := strconv.ParseUint(r.DsDigestType, 10, 8)
|
||||||
rc.DsDigestType = uint8(dsDigestType)
|
rc.DsDigestType = uint8(dsDigestType)
|
||||||
rc.DsDigest = r.Target
|
rc.DsDigest = r.Target
|
||||||
rc.SetTarget(r.Target)
|
rc.SetTarget(r.Target)
|
||||||
|
@@ -295,7 +295,7 @@ func (c *hednsProvider) GetZoneRecords(domain string) (models.Records, error) {
|
|||||||
|
|
||||||
rc := &models.RecordConfig{
|
rc := &models.RecordConfig{
|
||||||
Type: parser.parseStringAttr(element.Find("td > .rrlabel"), "data"),
|
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{
|
Original: Record{
|
||||||
ZoneName: domain,
|
ZoneName: domain,
|
||||||
ZoneID: domainID,
|
ZoneID: domainID,
|
||||||
@@ -308,7 +308,7 @@ func (c *hednsProvider) GetZoneRecords(domain string) (models.Records, error) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
priority := parser.parseIntElement(element.Find("td:nth-child(6)"))
|
priority := parser.parseIntElementUint16(element.Find("td:nth-child(6)"))
|
||||||
if parser.err != nil {
|
if parser.err != nil {
|
||||||
err = parser.err
|
err = parser.err
|
||||||
return false
|
return false
|
||||||
@@ -731,9 +731,9 @@ func (p *elementParser) parseStringElement(element *goquery.Selection) (result s
|
|||||||
return element.Text()
|
return element.Text()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *elementParser) parseIntElement(element *goquery.Selection) (result uint64) {
|
func (p *elementParser) parseIntElementUint16(element *goquery.Selection) uint16 {
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
return
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case to deal with Priority
|
// Special case to deal with Priority
|
||||||
@@ -741,6 +741,22 @@ func (p *elementParser) parseIntElement(element *goquery.Selection) (result uint
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
result, p.err = strconv.ParseUint(element.Text(), 10, 64)
|
var result64 uint64
|
||||||
return result
|
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 {
|
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{
|
rc := &models.RecordConfig{
|
||||||
Type: r.Type,
|
Type: r.Type,
|
||||||
@@ -101,7 +101,7 @@ func toRecordConfig(domain string, r *record) *models.RecordConfig {
|
|||||||
_ = rc.SetTarget(parts[3])
|
_ = rc.SetTarget(parts[3])
|
||||||
case "CAA":
|
case "CAA":
|
||||||
parts := strings.Split(r.Destination, " ")
|
parts := strings.Split(r.Destination, " ")
|
||||||
caaFlag, _ := strconv.ParseUint(parts[0], 10, 32)
|
caaFlag, _ := strconv.ParseUint(parts[0], 10, 8)
|
||||||
rc.CaaFlag = uint8(caaFlag)
|
rc.CaaFlag = uint8(caaFlag)
|
||||||
rc.CaaTag = parts[1]
|
rc.CaaTag = parts[1]
|
||||||
_ = rc.SetTarget(strings.Trim(parts[2], "\""))
|
_ = rc.SetTarget(strings.Trim(parts[2], "\""))
|
||||||
|
Reference in New Issue
Block a user