infra: fix golang coverage path to corpus (#9833)

Completes #9812
This commit is contained in:
Catena cyber 2023-03-07 09:50:16 +01:00 committed by GitHub
parent ce2f2e537c
commit a786f9777d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 4 deletions

View File

@ -15,6 +15,7 @@
package mypackagebeingfuzzed
import (
"io/fs"
"io/ioutil"
"os"
"path/filepath"
@ -28,6 +29,7 @@ func TestFuzzCorpus(t *testing.T) {
t.Logf("No fuzzing corpus directory set")
return
}
filename := ""
defer func() {
if r := recover(); r != nil {
t.Error("Fuzz panicked in "+filename, r)
@ -42,22 +44,22 @@ func TestFuzzCorpus(t *testing.T) {
_ = pprof.StartCPUProfile(f)
}
}
infos, err := ioutil.ReadDir(dir)
_, err := ioutil.ReadDir(dir)
if err != nil {
t.Logf("Not fuzzing corpus directory %s", err)
return
}
filename := ""
// recurse for regressions subdirectory
err = filepath.Walk(".", func(filename string, info fs.FileInfo, err error) error {
err = filepath.Walk(dir, func(fname string, info fs.FileInfo, err error) error {
if info.IsDir() {
return nil
}
data, err := ioutil.ReadFile(filename)
data, err := ioutil.ReadFile(fname)
if err != nil {
t.Error("Failed to read corpus file", err)
return err
}
filename = fname
FuzzFunction(data)
return nil
})