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

jgoerzen/nncp: src/go.cypherpunks.ru/nncp/v5/cmd/nncp-bundle/main.go; 57 LoC

Open
#15,623 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 [jgoerzen/nncp](https://www.github.com/jgoerzen/nncp) at [src/go.cypherpunks.ru/nncp/v5/cmd/nncp-bundle/main.go](https://github.com/jgoerzen/nncp/blob/46be2c9c706cd824fe78404bace49c88ec236bdd/src/go.cypherpunks.ru/nncp/v5/cmd/nncp-bundle/main.go#L123-L179)

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 which takes a reference to nodeId at line 125 may start a goroutine

[Click here to see the code in its original context.](https://github.com/jgoerzen/nncp/blob/46be2c9c706cd824fe78404bace49c88ec236bdd/src/go.cypherpunks.ru/nncp/v5/cmd/nncp-bundle/main.go#L123-L179)

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

```go
for nodeId, _ := range nodeIds {
sds["node"] = nodeId.String()
for job := range ctx.Jobs(&nodeId, nncp.TTx) {
pktName = filepath.Base(job.Fd.Name())
sds["pkt"] = pktName
if job.PktEnc.Nice > nice {
ctx.LogD("nncp-bundle", sds, "too nice")
job.Fd.Close() // #nosec G104
continue
}
if err = tarWr.WriteHeader(&tar.Header{
Format: tar.FormatUSTAR,
Name: nncp.NNCPBundlePrefix,
Mode: 0700,
Typeflag: tar.TypeDir,
}); err != nil {
log.Fatalln("Error writing tar header:", err)
}
if err = tarWr.WriteHeader(&tar.Header{
Format: tar.FormatPAX,
Name: strings.Join([]string{
nncp.NNCPBundlePrefix,
nodeId.String(),
ctx.SelfId.String(),
pktName,
}, "/"),
Mode: 0400,
Size: job.Size,
Typeflag: tar.TypeReg,
}); err != nil {
log.Fatalln("Error writing tar header:", err)
}
if _, err = nncp.CopyProgressed(
tarWr, job.Fd, "Tx",
nncp.SdsAdd(sds, nncp.SDS{
"pkt": nncp.Base32Codec.EncodeToString(job.HshValue[:]),
"fullsize": job.Size,
}),
ctx.ShowPrgrs,
); err != nil {
log.Fatalln("Error during copying to tar:", err)
}
job.Fd.Close() // #nosec G104
if err = tarWr.Flush(); err != nil {
log.Fatalln("Error during tar flushing:", err)
}
if err = bufStdout.Flush(); err != nil {
log.Fatalln("Error during stdout flushing:", err)
}
if *doDelete {
if err = os.Remove(job.Fd.Name()); err != nil {
log.Fatalln("Error during deletion:", err)
}
}
ctx.LogI("nncp-bundle", nncp.SdsAdd(sds, nncp.SDS{"size": job.Size}), "")
}
}

```

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 calling a goroutine:
digraph G {
"(Jobs, 2)" -> {}
}

```

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: 46be2c9c706cd824fe78404bace49c88ec236bdd

Contributor guide

No contributing guide indexed for this repository

Research direction

Read src/go.cypherpunks.ru/nncp/v5/cmd/nncp-bundle/main.go around lines 123-179, starting with the ctx.Jobs(&nodeId, nncp.TTx) call and the analyzer report. Decide whether the finding is a Bug, Mitigated, or Desirable Behavior, then leave the corresponding reaction on the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.