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

atomix/kubernetes-controller: pkg/controller/database.go; 24 LoC

Open
#15,203 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 [atomix/kubernetes-controller](https://www.github.com/atomix/kubernetes-controller) at [pkg/controller/database.go](https://github.com/atomix/kubernetes-controller/blob/0a9e82ef37df25cf567a4dbc18f35b2bb454bda1/pkg/controller/database.go#L87-L110)

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

[Click here to see the code in its original context.](https://github.com/atomix/kubernetes-controller/blob/0a9e82ef37df25cf567a4dbc18f35b2bb454bda1/pkg/controller/database.go#L87-L110)

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

```go
for _, database := range databases.Items {
pbdatabase := k8s.NewDatabaseProto(&database)

options := &client.ListOptions{
Namespace: k8s.GetDatabaseNamespace(databaseapi.DatabaseId{Namespace: request.Namespace}),
LabelSelector: labels.SelectorFromSet(k8s.GetPartitionLabelsForDatabase(&database)),
}
partitions := &v1beta3.PartitionList{}
err := c.client.List(context.TODO(), partitions, options)
if err != nil {
return nil, err
}

if len(partitions.Items) != int(database.Spec.Partitions) {
continue
}

pbpartitions := make([]databaseapi.Partition, 0, len(partitions.Items))
for _, partition := range partitions.Items {
pbpartitions = append(pbpartitions, *k8s.NewPartitionProto(&partition))
}
pbdatabase.Partitions = pbpartitions
pbdatabases = append(pbdatabases, *pbdatabase)
}

```

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: 0a9e82ef37df25cf567a4dbc18f35b2bb454bda1

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with pkg/controller/database.go lines 87-110 at commit 0a9e82ef37df25cf567a4dbc18f35b2bb454bda1 and review the range-loop references in the provided snippet. Check whether the referenced loop variables can produce incorrect database or partition data, then classify the finding as Bug, Mitigated, or Desirable Behavior based on the observed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
infrastructure
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.