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

nimbess/nimbess-cni: cmd/nimbess-cni.go; 34 LoC

Open
#15,406 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [nimbess/nimbess-cni](https://www.github.com/nimbess/nimbess-cni) at [cmd/nimbess-cni.go](https://github.com/nimbess/nimbess-cni/blob/92a1620a24a4206781ee1ea91dff704ec6879092/cmd/nimbess-cni.go#L265-L298)

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 ifidx was used in a composite literal at line 294

[Click here to see the code in its original context.](https://github.com/nimbess/nimbess-cni/blob/92a1620a24a4206781ee1ea91dff704ec6879092/cmd/nimbess-cni.go#L265-L298)

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

```go
for ifidx, iface := range r.Interfaces {
// append interface info
cniResult.Interfaces = append(cniResult.Interfaces, &cnitypes.Interface{
Name: iface.Name,
Mac: iface.Mac,
Sandbox: iface.Sandbox,
})
for _, ip := range iface.IpAddresses {
// append interface ip address info
ipAddr, ipNet, err := net.ParseCIDR(ip.Address)
if err != nil {
log.Error(err)
return err
}
ipNet.IP = ipAddr
var gwAddr net.IP
if ip.Gateway != "" {
gwAddr = net.ParseIP(ip.Gateway)
if gwAddr == nil {
log.Warningf("Failed to parse gateway: %s", ip.Gateway)
}
}
ver := "4"
if ip.Version == cninimbess.CNIReply_Interface_IP_IPV6 {
ver = "6"
}
cniResult.IPs = append(cniResult.IPs, &cnitypes.IPConfig{
Address: *ipNet,
Version: ver,
Interface: &ifidx,
Gateway: gwAddr,
})
}
}

```

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: 92a1620a24a4206781ee1ea91dff704ec6879092

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with cmd/nimbess-cni.go at lines 265-298 in commit 92a1620a24a4206781ee1ea91dff704ec6879092, focusing on the range variable ifidx and its use in the IPConfig composite literal. Review the analyzer finding and surrounding CNI interface/IP handling, then leave the reaction that matches whether this is a bug, mitigated, or desirable behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.