github-vet / github-vet/rangeloop-pointer-findings
drakkan/sftpgo: common/common.go; 19 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [drakkan/sftpgo](https://www.github.com/drakkan/sftpgo) at [common/common.go](https://github.com/drakkan/sftpgo/blob/30eb3c4a99c2c6caf53e43736f1b3dba565556f6/common/common.go#L527-L545)
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 c used in defer or goroutine at line 537
[Click here to see the code in its original context.](https://github.com/drakkan/sftpgo/blob/30eb3c4a99c2c6caf53e43736f1b3dba565556f6/common/common.go#L527-L545)
Click here to show the 19 line(s) of Go which triggered the analyzer.
```go
for _, c := range conns.connections {
idleTime := time.Since(c.GetLastActivity())
isUnauthenticatedFTPUser := (c.GetProtocol() == ProtocolFTP && len(c.GetUsername()) == 0)
if idleTime > Config.idleTimeoutAsDuration || (isUnauthenticatedFTPUser && idleTime > Config.idleLoginTimeout) {
defer func(conn ActiveConnection, isFTPNoAuth bool) {
err := conn.Disconnect()
logger.Debug(conn.GetProtocol(), conn.GetID(), "close idle connection, idle time: %v, username: %#v close err: %v",
time.Since(conn.GetLastActivity()), conn.GetUsername(), err)
if isFTPNoAuth {
ip := utils.GetIPFromRemoteAddress(c.GetRemoteAddress())
logger.ConnectionFailedLog("", ip, dataprovider.LoginMethodNoAuthTryed, c.GetProtocol(), "client idle")
metrics.AddNoAuthTryed()
dataprovider.ExecutePostLoginHook("", dataprovider.LoginMethodNoAuthTryed, ip, c.GetProtocol(),
dataprovider.ErrNoAuthTryed)
}
}(c, isUnauthenticatedFTPUser)
}
}
```
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: 30eb3c4a99c2c6caf53e43736f1b3dba565556f6
Contributor guide
No contributing guide indexed for this repository
Research direction
Read common/common.go around lines 527-545 and inspect the deferred closure's use of c versus its conn parameter. Check the surrounding connection and idle-timeout entry point, then determine whether the analyzer finding represents a real bug, mitigated behavior, or desirable behavior; leave the corresponding classification reaction when the evidence is clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100