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

pchaigno/syzkaller-tmp: sys/syz-sysgen/sysgen.go; 85 LoC

Open
#12,880 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 [pchaigno/syzkaller-tmp](https://www.github.com/pchaigno/syzkaller-tmp) at [sys/syz-sysgen/sysgen.go](https://github.com/pchaigno/syzkaller-tmp/blob/6deb685bc9d0876d1577948abea422799f0cd3c9/sys/syz-sysgen/sysgen.go#L62-L146)

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 OS used in defer or goroutine at line 95

[Click here to see the code in its original context.](https://github.com/pchaigno/syzkaller-tmp/blob/6deb685bc9d0876d1577948abea422799f0cd3c9/sys/syz-sysgen/sysgen.go#L62-L146)

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

```go
for OS, archs := range targets.List {
top := ast.ParseGlob(filepath.Join("sys", OS, "*.txt"), nil)
if top == nil {
os.Exit(1)
}
osutil.MkdirAll(filepath.Join("sys", OS, "gen"))

type Job struct {
Target *targets.Target
OK bool
Errors []string
Unsupported map[string]bool
ArchData ArchData
}
var jobs []*Job
for _, target := range archs {
jobs = append(jobs, &Job{
Target: target,
})
}
sort.Slice(jobs, func(i, j int) bool {
return jobs[i].Target.Arch < jobs[j].Target.Arch
})
var wg sync.WaitGroup
wg.Add(len(jobs))

for _, job := range jobs {
job := job
go func() {
defer wg.Done()
eh := func(pos ast.Pos, msg string) {
job.Errors = append(job.Errors, fmt.Sprintf("%v: %v\n", pos, msg))
}
consts := compiler.DeserializeConstsGlob(filepath.Join("sys", OS, "*_"+job.Target.Arch+".const"), eh)
if consts == nil {
return
}
prog := compiler.Compile(top, consts, job.Target, eh)
if prog == nil {
return
}
job.Unsupported = prog.Unsupported

sysFile := filepath.Join("sys", OS, "gen", job.Target.Arch+".go")
out := new(bytes.Buffer)
generate(job.Target, prog, consts, out)
rev := hash.String(out.Bytes())
fmt.Fprintf(out, "const revision_%v = %q\n", job.Target.Arch, rev)
writeSource(sysFile, out.Bytes())

job.ArchData = generateExecutorSyscalls(job.Target, prog.Syscalls, rev)

job.OK = true
}()
}
writeEmpty(OS)
wg.Wait()

var syscallArchs []ArchData
unsupported := make(map[string]int)
for _, job := range jobs {
fmt.Printf("generating %v/%v...\n", job.Target.OS, job.Target.Arch)
for _, msg := range job.Errors {
fmt.Print(msg)
}
if !job.OK {
os.Exit(1)
}
syscallArchs = append(syscallArchs, job.ArchData)
for u := range job.Unsupported {
unsupported[u]++
}
fmt.Printf("\n")
}
oses = append(oses, OSData{
GOOS: OS,
Archs: syscallArchs,
})

for what, count := range unsupported {
if count == len(jobs) {
failf("%v is unsupported on all arches (typo?)", what)
}
}
}

```

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: 6deb685bc9d0876d1577948abea422799f0cd3c9

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.