github-vet / github-vet/rangeloop-pointer-findings
Rrooach/rtfuzzer: sys/syz-sysgen/sysgen.go; 108 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [Rrooach/rtfuzzer](https://www.github.com/Rrooach/rtfuzzer) at [sys/syz-sysgen/sysgen.go](https://github.com/Rrooach/rtfuzzer/blob/60110ef2b3ac9eeca5edf403c48598e066d0095e/sys/syz-sysgen/sysgen.go#L73-L180)
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 118
[Click here to see the code in its original context.](https://github.com/Rrooach/rtfuzzer/blob/60110ef2b3ac9eeca5edf403c48598e066d0095e/sys/syz-sysgen/sysgen.go#L73-L180)
Click here to show the 108 line(s) of Go which triggered the analyzer.
```go
for _, OS := range OSList {
descriptions := ast.ParseGlob(filepath.Join(*srcDir, "sys", OS, "*.txt"), nil)
if descriptions == nil {
os.Exit(1)
}
constFile := compiler.DeserializeConstFile(filepath.Join(*srcDir, "sys", OS, "*.const"), nil)
if constFile == nil {
os.Exit(1)
}
osutil.MkdirAll(filepath.Join(*outDir, "sys", OS, "gen"))
var archs []string
for arch := range targets.List[OS] {
archs = append(archs, arch)
}
sort.Strings(archs)
type Job struct {
Target *targets.Target
OK bool
Errors []string
Unsupported map[string]bool
ArchData ArchData
}
var jobs []*Job
for _, arch := range archs {
jobs = append(jobs, &Job{
Target: targets.List[OS][arch],
})
}
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 := constFile.Arch(job.Target.Arch)
top := descriptions
if OS == "linux" && (job.Target.Arch == "arm" || job.Target.Arch == "riscv64") {
// Hack: KVM is not supported on ARM anymore. On riscv64 it
// is not supported yet but might be in the future.
// Note: syz-extract also ignores this file for arm and
// riscv64.
top = descriptions.Filter(func(n ast.Node) bool {
pos, _, _ := n.Info()
return !strings.HasSuffix(pos.File, "_kvm.txt")
})
}
if OS == "test" {
constInfo := compiler.ExtractConsts(top, job.Target, eh)
compiler.FabricateSyscallConsts(job.Target, constInfo, consts)
}
prog := compiler.Compile(top, consts, job.Target, eh)
if prog == nil {
return
}
job.Unsupported = prog.Unsupported
sysFile := filepath.Join(*outDir, "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)
// Don't print warnings, they are printed in syz-check.
job.Errors = nil
job.OK = true
}()
}
writeEmpty(OS)
wg.Wait()
var syscallArchs []ArchData
unsupported := make(map[string]int)
for _, job := range jobs {
if !job.OK {
fmt.Printf("compilation of %v/%v target failed:\n", job.Target.OS, job.Target.Arch)
for _, msg := range job.Errors {
fmt.Print(msg)
}
os.Exit(1)
}
syscallArchs = append(syscallArchs, job.ArchData)
for u := range job.Unsupported {
unsupported[u]++
}
}
data.OSes = append(data.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: 60110ef2b3ac9eeca5edf403c48598e066d0095e
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.