github-vet / github-vet/rangeloop-pointer-findings
sandromello/wgadmin: pkg/cli/peers.go; 41 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [sandromello/wgadmin](https://www.github.com/sandromello/wgadmin) at [pkg/cli/peers.go](https://github.com/sandromello/wgadmin/blob/ab4c90de0b87ee96e36f607b0ed2573c428a44bc/pkg/cli/peers.go#L44-L84)
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 new was used in a composite literal at line 60
[Click here to see the code in its original context.](https://github.com/sandromello/wgadmin/blob/ab4c90de0b87ee96e36f607b0ed2573c428a44bc/pkg/cli/peers.go#L44-L84)
Click here to show the 41 line(s) of Go which triggered the analyzer.
```go
for _, new := range peerList {
peerServer := new.GetServer()
// TODO: There's no need to fetch a server for every single peer config, improve later
wgsc, err := client.WireguardServerConfig().Get(peerServer)
if err != nil || wgsc == nil {
return fmt.Errorf("failed fetching server %v, err=%v", peerServer, err)
}
old, err := client.Peer().Get(new.UID)
if err != nil {
return fmt.Errorf("failed fetching peer %s, err=%v", new.UID, err)
}
ipmap, err := buildIPMap(client, wgsc)
if err != nil {
return err
}
if old == nil {
if err := validatePeer(&new); err != nil {
return fmt.Errorf("failed validating peer %s, err=%v", new.UID, err)
}
ipaddr := new.ParseAllowedIPs()
if !ipmap.IsAvailable(ipaddr) {
return fmt.Errorf("peer %s has ip %q which isn't available for network %v", new.UID, ipaddr.String(), ipmap.Net.String())
}
new.CreatedAt = time.Now().UTC().Format(time.RFC3339)
if err := client.Peer().Update(&new); err != nil {
return fmt.Errorf("failed creating new peer %s, err=%v", new.UID, err)
}
success++
} else if !reflect.DeepEqual(old.Spec, new.Spec) {
ipaddr := new.ParseAllowedIPs()
if old.Spec.AllowedIPs != new.Spec.AllowedIPs && !ipmap.IsAvailable(ipaddr) {
return fmt.Errorf("peer %s has ip %q which isn't available for network %v", new.UID, ipaddr.String(), ipmap.Net.String())
}
new.Metadata = old.Metadata
new.Status = old.Status
if err := client.Peer().Update(&new); err != nil {
return fmt.Errorf("failed updating peer %s, err=%v", new.UID, err)
}
success++
}
}
```
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: ab4c90de0b87ee96e36f607b0ed2573c428a44bc
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.