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

cisco-sso/snapshotpolicy: strategy/inuse.go; 15 LoC

Open
#15,866 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 [cisco-sso/snapshotpolicy](https://www.github.com/cisco-sso/snapshotpolicy) at [strategy/inuse.go](https://github.com/cisco-sso/snapshotpolicy/blob/c5dc7fc4388e33ca32c5abc2141d49bef7c60449/strategy/inuse.go#L220-L234)

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

[Click here to see the code in its original context.](https://github.com/cisco-sso/snapshotpolicy/blob/c5dc7fc4388e33ca32c5abc2141d49bef7c60449/strategy/inuse.go#L220-L234)

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

```go
for _, volSnap := range existingSnaps.Items {
// Only get the snapshots for my policy, for this claim
// TODO: Label selectors would be better, however strat.client does not have a clientset
if policyLabel, ok := volSnap.GetObjectMeta().GetLabels()[PolicyLabelKey]; ok {
if claimLabel, ok := volSnap.GetObjectMeta().GetLabels()[ClaimLabelKey]; ok {
if policyLabel == policy.GetObjectMeta().GetName() && claimLabel == claimName {
dates = append(dates,
snapshotDate{
Snapshot: &volSnap,
Time: volSnap.GetObjectMeta().GetCreationTimestamp(),
})
}
}
}
}

```

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: c5dc7fc4388e33ca32c5abc2141d49bef7c60449

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading strategy/inuse.go lines 220-234 and the linked range-loop finding; trace how dates and snapshotDate are consumed. Confirm whether the volSnap reference can produce incorrect results, then define a regression check for the affected behavior; done means the finding is resolved without changing intended snapshot selection.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
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.