github-vet / github-vet/rangeloop-pointer-findings
jtolio/gitserve: ssh/ssh.go; 82 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [jtolio/gitserve](https://www.github.com/jtolio/gitserve) at [ssh/ssh.go](https://github.com/jtolio/gitserve/blob/820b4285c69bf6b3df9afdf57a4e30346befab1d/ssh/ssh.go#L63-L144)
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 req used in defer or goroutine at line 136
[Click here to see the code in its original context.](https://github.com/jtolio/gitserve/blob/820b4285c69bf6b3df9afdf57a4e30346befab1d/ssh/ssh.go#L63-L144)
Click here to show the 82 line(s) of Go which triggered the analyzer.
```go
for req := range reqs {
switch req.Type {
case "pty-req":
pty_requested = true
err := req.Reply(true, nil)
if err != nil {
return err
}
continue
case "shell":
err := req.Reply(true, nil)
if err != nil {
return err
}
if r.MOTD != "" {
_, err = ch.Stderr().Write([]byte(r.MOTD))
if err != nil {
return err
}
}
if r.ShellError != "" {
_, err = ch.Stderr().Write([]byte(r.ShellError))
if err != nil {
return err
}
}
return writeExitStatus(ch, 1)
case "env":
err := req.Reply(false, nil)
if err != nil {
return err
}
continue
}
if req.Type != "exec" || exec_happened || pty_requested ||
len(req.Payload) < 4 {
err := req.Reply(false, nil)
if err != nil {
return err
}
continue
}
exec_happened = true
payload_len := binary.BigEndian.Uint32(req.Payload[:4])
if len(req.Payload)-4 != int(payload_len) {
// it's unclear to me what's going on here - i so far haven't found
// documentation (though i haven't looked very hard) about what a request
// payload is supposed to be and why it seems like the network endian
// size of it is a prefix, even though the payload already has a length
// in go-land. unsure if this is a library-specific issue or part of the
// ssh protocol expectations. anyway, be paranoid. kill everything if
// my assumption is wrong.
panic(fmt.Sprintf("whups, bad assumption, %d != %d",
len(req.Payload)-4, payload_len))
}
err := req.Reply(true, nil)
if err != nil {
return err
}
go func() {
defer ch.Close()
if r.MOTD != "" {
_, err = ch.Stderr().Write([]byte(r.MOTD))
if err != nil {
logger.Errore(err)
logger.Errore(writeExitStatus(ch, 1))
return
}
}
exit_status, err := r.handleExec(ch, string(req.Payload[4:]), meta)
if err != nil {
logger.Errore(err)
logger.Errore(writeExitStatus(ch, 1))
} else {
logger.Errore(writeExitStatus(ch, exit_status))
}
}()
}
```
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: 820b4285c69bf6b3df9afdf57a4e30346befab1d
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.