github-vet / github-vet/rangeloop-pointer-findings
mattermost/mattermost-server: cmd/mattermost/commands/webhook.go; 40 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [mattermost/mattermost-server](https://www.github.com/mattermost/mattermost-server) at [cmd/mattermost/commands/webhook.go](https://github.com/mattermost/mattermost-server/blob/40e16ba07f08102bcf92b263fa885677c223ad4c/cmd/mattermost/commands/webhook.go#L109-L148)
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.
> range-loop variable team used in defer or goroutine at line 118
[Click here to see the code in its original context.](https://github.com/mattermost/mattermost-server/blob/40e16ba07f08102bcf92b263fa885677c223ad4c/cmd/mattermost/commands/webhook.go#L109-L148)
Click here to show the 40 line(s) of Go which triggered the analyzer.
```go
for i, team := range teams {
if team == nil {
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
continue
}
// Fetch all hooks with a very large limit so we get them all.
incomingResult := make(chan store.StoreResult, 1)
go func() {
incomingHooks, err := app.Srv().Store.Webhook().GetIncomingByTeam(team.Id, 0, 100000000)
incomingResult <- store.StoreResult{Data: incomingHooks, NErr: err}
close(incomingResult)
}()
outgoingResult := make(chan store.StoreResult, 1)
go func() {
outgoingHooks, err := app.Srv().Store.Webhook().GetOutgoingByTeam(team.Id, 0, 100000000)
outgoingResult <- store.StoreResult{Data: outgoingHooks, NErr: err}
close(outgoingResult)
}()
if result := <-incomingResult; result.NErr == nil {
CommandPrettyPrintln(fmt.Sprintf("Incoming webhooks for %s (%s):", team.DisplayName, team.Name))
hooks := result.Data.([]*model.IncomingWebhook)
for _, hook := range hooks {
CommandPrettyPrintln("\t" + hook.DisplayName + " (" + hook.Id + ")")
}
} else {
CommandPrintErrorln("Unable to list incoming webhooks for '" + args[i] + "'")
}
if result := <-outgoingResult; result.NErr == nil {
hooks := result.Data.([]*model.OutgoingWebhook)
CommandPrettyPrintln(fmt.Sprintf("Outgoing webhooks for %s (%s):", team.DisplayName, team.Name))
for _, hook := range hooks {
CommandPrettyPrintln("\t" + hook.DisplayName + " (" + hook.Id + ")")
}
} else {
CommandPrintErrorln("Unable to list outgoing webhooks for '" + args[i] + "'")
}
}
```
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: 40e16ba07f08102bcf92b263fa885677c223ad4c
Contributor guide
No contributing guide indexed for this repository
Research direction
The finding is in cmd/mattermost/commands/webhook.go around lines 109-148; start by reading the loop and its two goroutines, then examine the reported range-variable capture. Check the behavior with multiple teams and classify the finding as a bug, mitigated, or desirable behavior. Done means leaving the appropriate reaction on the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100