github-vet / github-vet/rangeloop-pointer-findings

jmesserli/nx: ns/dns/zonegenerator.go; 66 LoC

Open
#16,516 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [jmesserli/nx](https://www.github.com/jmesserli/nx) at [ns/dns/zonegenerator.go](https://github.com/jmesserli/nx/blob/19c791b981b1c883d67dfb5d9db94191a1152914/ns/dns/zonegenerator.go#L160-L225)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to address was used in a composite literal at line 161

[Click here to see the code in its original context.](https://github.com/jmesserli/nx/blob/19c791b981b1c883d67dfb5d9db94191a1152914/ns/dns/zonegenerator.go#L160-L225)

Click here to show the 66 line(s) of Go which triggered the analyzer.

```go
for _, address := range addresses {
dnsIP := DNSIP{IP: &address}
tagparser.ParseTags(&dnsIP, address.Tags, address.Prefix.Tags)

if !dnsIP.Enabled {
continue
}

FixFlattenAddress(&dnsIP)

ip, _, _ := net.ParseCIDR(address.Address)
isIP4 := strings.Count(ip.String(), ":") < 2

if len(dnsIP.ForwardZoneName) > 0 {
var recordType rrType
if isIP4 {
recordType = A
} else {
recordType = Aaaa
}

putMap(zoneRecordsMap, dnsIP.ForwardZoneName, resourceRecord{
Name: address.Name,
Type: recordType,
RData: ip.String(),
})

for _, cname := range dnsIP.CNames {
putMap(zoneRecordsMap, dnsIP.ForwardZoneName, resourceRecord{
Name: cname,
Type: CName,
RData: address.Name,
})
}
}

if len(dnsIP.ReverseZoneName) > 0 {
zoneName, err := ipToNibble(dnsIP.ReverseZoneName, true)
if err != nil {
logger.Printf("Could not parse cidr <%v> of %v", dnsIP.ReverseZoneName, address)
continue
}

if len(dnsIP.ForwardZoneName) == 0 {
// Parse parent tags to restore forward zone name
tagparser.ParseTags(&dnsIP, address.Prefix.Tags, []model.Tag{})
}

name, err := ipToNibble(address.Address, false)
if err != nil {
logger.Printf("Could not parse cidr <%v> of %v", address.Address, address)
continue
}

name = name[:len(name)-len(zoneName)-1]

rData := fmt.Sprintf("%s.%s", address.Name, dnsIP.ForwardZoneName)
rData = strings.TrimRight(rData, ".")
rData = rData + "."
putMap(zoneRecordsMap, zoneName, resourceRecord{
Name: name,
Type: Ptr,
RData: rData,
})
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 19c791b981b1c883d67dfb5d9db94191a1152914

Contributor guide

No contributing guide indexed for this repository

Research direction

Inspect ns/dns/zonegenerator.go at lines 160-225, focusing on the range over addresses and the reference used to construct DNSIP. Compare the analyzer's warning with the surrounding DNS record generation, then classify the finding as Bug, Mitigated, or Desirable Behavior by leaving the corresponding reaction.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.