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

contiv/vpp: cmd/contiv-cni/contiv_cni.go; 34 LoC

Open
#12,644 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 [contiv/vpp](https://www.github.com/contiv/vpp) at [cmd/contiv-cni/contiv_cni.go](https://github.com/contiv/vpp/blob/c6ed55900e77dd14b8705dc6fa6d90f7a8b70b56/cmd/contiv-cni/contiv_cni.go#L191-L224)

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 220

[Click here to see the code in its original context.](https://github.com/contiv/vpp/blob/c6ed55900e77dd14b8705dc6fa6d90f7a8b70b56/cmd/contiv-cni/contiv_cni.go#L191-L224)

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, &cnisb.Interface{
Name: iface.Name,
Mac: iface.Mac,
Sandbox: iface.Sandbox,
})
for _, ip := range iface.IpAddresses {
// append interface ip address info
_, ipAddr, err := net.ParseCIDR(ip.Address)
if err != nil {
log.Error(err)
return err
}
var gwAddr net.IP
if ip.Gateway != "" {
gwAddr = net.ParseIP(ip.Gateway)
if err != nil {
log.Error(err)
return err
}
}
ver := "4"
if ip.Version == cninb.CNIReply_Interface_IP_IPV6 {
ver = "6"
}
cniResult.IPs = append(cniResult.IPs, &cnisb.IPConfig{
Address: *ipAddr,
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: c6ed55900e77dd14b8705dc6fa6d90f7a8b70b56

Contributor guide

No contributing guide indexed for this repository

Research direction

Read cmd/contiv-cni/contiv_cni.go at lines 191-224 and inspect the linked commit context around the analyzer finding about ifidx. Decide whether the reported range-loop reference is a Bug, Mitigated, or Desirable Behavior, then leave the corresponding reaction requested in the issue.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.