github-vet / github-vet/rangeloop-pointer-findings
bluek8s/kubedirector: pkg/controller/secret/secret.go; 60 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [bluek8s/kubedirector](https://www.github.com/bluek8s/kubedirector) at [pkg/controller/secret/secret.go](https://github.com/bluek8s/kubedirector/blob/5fca5b9b3708829a252b036e98ac5297e2f84875/pkg/controller/secret/secret.go#L64-L123)
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.
>
[Click here to see the code in its original context.](https://github.com/bluek8s/kubedirector/blob/5fca5b9b3708829a252b036e98ac5297e2f84875/pkg/controller/secret/secret.go#L64-L123)
Click here to show the 60 line(s) of Go which triggered the analyzer.
```go
for _, kubecluster := range allClusters.Items {
if isClusterUsingSecret(secret.Name, kubecluster) {
shared.LogInfof(
reqLogger,
&kubecluster,
shared.EventReasonSecret,
"connected secret {%s} has changed",
secret.Name,
)
shared.LogInfof(
reqLogger,
secret,
shared.EventReasonCluster,
"connected to cluster {%s}; updating it",
kubecluster.Name,
)
//Notify cluster by incrementing configmetaGenerator
wait := time.Second
maxWait := 4096 * time.Second
for {
updateMetaGenerator := &kubecluster
annotations := updateMetaGenerator.Annotations
if annotations == nil {
annotations = make(map[string]string)
updateMetaGenerator.Annotations = annotations
}
if v, ok := annotations[shared.ConnectionsIncrementor]; ok {
newV, _ := strconv.Atoi(v)
annotations[shared.ConnectionsIncrementor] = strconv.Itoa(newV + 1)
} else {
annotations[shared.ConnectionsIncrementor] = "1"
}
updateMetaGenerator.Annotations = annotations
if shared.Update(context.TODO(), updateMetaGenerator) == nil {
break
}
// Since update failed, get a fresh copy of this cluster to work with and
// try update
updateMetaGenerator, fetchErr := observer.GetCluster(kubecluster.Namespace, kubecluster.Name)
if fetchErr != nil {
if errors.IsNotFound(fetchErr) {
break
}
}
if wait > maxWait {
shared.LogErrorf(
reqLogger,
fmt.Errorf("failed to update cluster"),
secret,
shared.EventReasonSecret,
"Unable to notify cluster {%s} of configmeta change",
updateMetaGenerator.Name)
break
}
time.Sleep(wait)
wait = wait * 2
}
}
}
```
Click here to show extra information the analyzer produced.
```
No path was found through the callgraph that could lead to a function which writes a pointer argument.
No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.
root signature {LogInfof 5} was not found in the callgraph; reference was passed directly to third-party code
```
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: 5fca5b9b3708829a252b036e98ac5297e2f84875
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading pkg/controller/secret/secret.go around lines 64-123 at commit 5fca5b9, focusing on the range over allClusters.Items and the analyzer's pointer-related report. Trace whether the captured cluster reference can cause incorrect behavior, then classify the finding as Bug, Mitigated, or Desirable Behavior with the corresponding reaction; no code change is specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100