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

openshift/compliance-operator: cmd/manager/suitererunner.go; 38 LoC

Open
#18,383 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 [openshift/compliance-operator](https://www.github.com/openshift/compliance-operator) at [cmd/manager/suitererunner.go](https://github.com/openshift/compliance-operator/blob/3d86842cf889af96db7b2b07cdcd9d08bf77b10d/cmd/manager/suitererunner.go#L90-L127)

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 scan is reassigned at line 91

[Click here to see the code in its original context.](https://github.com/openshift/compliance-operator/blob/3d86842cf889af96db7b2b07cdcd9d08bf77b10d/cmd/manager/suitererunner.go#L90-L127)

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

```go
for _, scan := range scans.Items {
currentScan := &scan
key := types.NamespacedName{Name: scan.GetName(), Namespace: scan.GetNamespace()}
err := backoff.Retry(func() error {
var scanCopy *compv1alpha1.ComplianceScan
if currentScan == nil {
fmt.Printf("Re-fetching ComplianceScan '%s' since the reference we had is no longer valid\n", scanCopy.Name)
err = conf.client.client.Get(context.TODO(), key, currentScan)
if err != nil {
fmt.Printf("Error re-fetching ComplianceScan '%s': %s\n", scanCopy.Name, err)
return err
}
} else {
scanCopy = currentScan.DeepCopy()
}
if scanCopy.Annotations == nil {
scanCopy.Annotations = make(map[string]string)
}
scanCopy.Annotations[compv1alpha1.ComplianceScanRescanAnnotation] = ""

fmt.Printf("Re-running ComplianceScan '%s'\n", scanCopy.Name)
err := conf.client.client.Update(context.TODO(), scanCopy)
if err != nil && (errors.IsResourceExpired(err) || errors.IsConflict(err)) {
currentScan = nil
return err
} else if err != nil {
fmt.Printf("Error while updating scan '%s', err: %s\n", scanCopy.Name, err)
fmt.Printf("Retrying.\n")
return err
}
return nil
}, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), maxScanUpdateRetries))

if err != nil {
fmt.Printf("Couldn't update scan '%s', err: %s\n", scan.Name, err)
os.Exit(1)
}
}

```

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: 3d86842cf889af96db7b2b07cdcd9d08bf77b10d

Contributor guide

No contributing guide indexed for this repository

Research direction

Read cmd/manager/suitererunner.go lines 90-127 and the analyzer message about reassigning the scan reference. Trace the range-loop and retry/update behavior, then determine whether the reference can cause incorrect scan handling; done means classifying the finding as Bug, Mitigated, or Desirable Behavior.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.