Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kalexmills opened this issue Nov 22, 2020 · 1 comment
Open

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

kalexmills opened this issue Nov 22, 2020 · 1 comment
Labels
bug Something isn't working false-positive the issue can create a false-positive vet-bot the issue is part of VetBot's responsibility

Comments

@kalexmills
Copy link
Contributor

kalexmills commented Nov 22, 2020

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
               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 kalexmills added bug Something isn't working false-positive the issue can create a false-positive labels Nov 22, 2020
@kalexmills kalexmills added the vet-bot the issue is part of VetBot's responsibility label Dec 3, 2020
@kalexmills
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working false-positive the issue can create a false-positive vet-bot the issue is part of VetBot's responsibility
Projects
None yet
Development

No branches or pull requests

1 participant