github-vet / github-vet/preliminary-findings-jan-2021
kylelemons/blightbot: commander/commander.go; 81 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Found a possible issue in [kylelemons/blightbot](https://www.github.com/kylelemons/blightbot) at [commander/commander.go](https://github.com/kylelemons/blightbot/blob/1879c832b3611d4cd7dd733087a3fb000255582e/commander/commander.go#L150-L230)
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 e used in defer or goroutine at line 196
[Click here to see the code in its original context.](https://github.com/kylelemons/blightbot/blob/1879c832b3611d4cd7dd733087a3fb000255582e/commander/commander.go#L150-L230)
Click here to show the 81 line(s) of Go which triggered the analyzer.
```go
for e := range events {
// Ignore malformatted messages
if len(e.msg.Args) < 2 || len(e.msg.Args[1]) == 0 {
continue
}
// Determine if it is a command (CTCP or with the leader char)
text, ctcp := e.msg.Args[1], false
switch text[0] {
case 0x01:
text, ctcp = DecodeCTCP(text), true
case startchar:
text = text[1:]
default:
if e.name == bot.ON_CHANMSG {
continue
}
}
if text == "" {
continue
}
// Parse the command into arguments
command, args := "", strings.Fields(text)
command, args = args[0], args[1:]
// Look up the command
cmd, ok := cmdmap[strings.ToUpper(command)]
if !ok {
continue
}
// Build the reply
replies := make(chan *bot.Message, 10)
go func() {
if ctcp {
for m := range replies {
switch m.Command {
case bot.CMD_PRIVMSG:
fallthrough
case bot.CMD_NOTICE:
if len(m.Args) > 1 {
m.Args[1] = EncodeCTCP(m.Args[1])
}
}
e.srv.WriteMessage(m)
}
return
}
for m := range replies {
e.srv.WriteMessage(m)
}
}()
resp := &Response{
out: replies,
}
src := &Source{
server: e.srv,
message: e.msg,
}
// Set the public/private responses
nick := e.msg.ID().Nick
switch e.name {
case bot.ON_CHANMSG:
resp.public = e.msg.Args[0]
resp.private = nick
case bot.ON_PRIVMSG:
resp.public = nick
resp.private = nick
case bot.ON_NOTICE:
resp.public = ""
resp.private = ""
}
// Call the hook
for _, cmd := range cmd {
cmd.hook.call(src, resp, command, args)
}
}
```
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: 1879c832b3611d4cd7dd733087a3fb000255582e
Contributor guide
No contributing guide indexed for this repository
Research direction
Read commander/commander.go around lines 150-230 and inspect the reported range-loop variable e used by the goroutine. Trace how events and replies are handled, then verify that each goroutine operates on the intended event; done means the reported finding is resolved without changing message handling 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