github-vet / bots

Bots for running analysis on GitHub's public Go repositories and crowdsourcing their classification.
MIT License
1 stars 1 forks source link

Range loops with ignored variables result in false-positives #19

Open kalexmills opened 3 years ago

kalexmills commented 3 years ago

There's another false positive which can occur when a range loop ignores all of its variables, as seen in this finding.

This range loop ranges over a channel and ignores the results returned from the ticker.

Click here for code ```go for _ = range ticker.C { ch := make(chan bool) go func() { err = a.Client.Call(a.ctx, "GetInfo", &common.ServerInfo, &common.Config) if err != nil { a.log("RPC Client Call:", err.Error()) return } ch <- true }() // Server集群列表获取 select { case <-ch: serverList, err := a.getServerList() if err != nil { a.log("RPC Client Call:", err.Error()) break } if len(serverList) == 0 { a.log("No server node available") break } if len(serverList) == len(a.ServerList) { for i, server := range serverList { // TODO 可能会产生问题 if server != a.ServerList[i] { a.ServerList = serverList // 防止正在传输重置client导致数据丢失 a.Mutex.Lock() a.Client.Close() a.newClient() a.Mutex.Unlock() break } } } else { a.log("Server nodes from old to new:", a.ServerList, "->", serverList) a.ServerList = serverList a.Mutex.Lock() a.Client.Close() a.newClient() a.Mutex.Unlock() } case <-time.NewTicker(time.Second * 3).C: break } } ```
kalexmills commented 3 years ago

Considering wontfix for this, since I'm not seeing enough instances in practice.