github-vet / github-vet/rangeloop-pointer-findings

hackerlist/monty: app/controllers/probe.go; 76 LoC

Open
#14,549 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [hackerlist/monty](https://www.github.com/hackerlist/monty) at [app/controllers/probe.go](https://github.com/hackerlist/monty/blob/d79daf5bf53215e13cf1fe6344ff9164596959ca/app/controllers/probe.go#L40-L115)

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.

> function call at line 112 may store a reference to n

[Click here to see the code in its original context.](https://github.com/hackerlist/monty/blob/d79daf5bf53215e13cf1fe6344ff9164596959ca/app/controllers/probe.go#L40-L115)

Click here to show the 76 line(s) of Go which triggered the analyzer.

```go
for _, n := range nodes {
revel.TRACE.Printf("node %d", n.Id)
probes = nil
_, err := txn.Select(&probes, "select * from probe where nid=$1 order by id", n.Id)
if err != nil {
revel.ERROR.Printf("runchecks: %s", err)
continue
}

for _, p := range probes {
/* make sure we run the test at the right frequency */
last := p.LastRun
if t.Sub(last).Seconds() < p.Frequency {
revel.INFO.Printf("skipping probe %d - timeout not hit", p.Id)
/* not enough time elapsed - skip */
continue
}

/* get the script for this probe */
script, err := txn.Get(&models.Script{}, p.ScriptId)
if err != nil {
/* if we can't get the script, the probe can't be run */
revel.ERROR.Printf("can't run probe: missing script %d", p.ScriptId)
continue
}

if script == nil {
revel.ERROR.Printf("can't run probe: missing script %d", p.ScriptId)
continue
}

/* set up and run the probe via revel jobs api.
* the result comes back through the Error channel. */

scr := script.(*models.Script)

revel.TRACE.Printf("node %d probe %d script (%d) %q args %s", n.Id, p.Id, scr.Id, scr.Code, p.Arguments)
prunner := NewProbeRunner(&p, scr)

jobs.Now(prunner)

res := &models.Result{
NodeId: n.Id,
ProbeId: p.Id,
}

err = <-prunner.Error
if err != nil {
res.Passed = false
res.StatusMsg = err.Error()
} else {
res.Passed = true
res.StatusMsg = ""
}
res.Timestamp = time.Now()
err = txn.Insert(res)
if err != nil {
revel.ERROR.Printf("runchecks: %s", err)
continue
}
p.LastResultId = res.Id
_, err = txn.Update(&p)
if err != nil {
revel.ERROR.Printf("runchecks: %s", err)
continue
}

revel.TRACE.Printf("probe passed? %d %t %q", p.Id, res.Passed, res.StatusMsg)

// if the probe failed, send the result to the callback url in the node.
if res.Passed == false {
revel.WARN.Printf("probe failed, running callback")
go pjob.Failed(&n, &p, res)
}
}
}

```

Click here to show extra information the analyzer produced.

```
The following graphviz dot graph describes paths through the callgraph that could lead to a function which writes a pointer argument:
digraph G {
"(Failed, 3)" -> {}
}

No path was found through the callgraph that could lead to a function which passes a pointer to third-party code.

```

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: d79daf5bf53215e13cf1fe6344ff9164596959ca

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.