Skip to content

Commit

Permalink
go-fuzz-build: load reflect when using libfuzzer
Browse files Browse the repository at this point in the history
libfuzzer's generated main function uses package reflect.
When attempting to build a package that doesn't depend
on reflect, such as github.com/dvyukuv/go-fuzz-corpus/{bzip2,gif,url},
package reflect wasn't getting copied to GOROOT, and the build failed.

Fix that.

We may need something similar in the future for fuzz.F; see #223.

Updates google/oss-fuzz/#2188
  • Loading branch information
josharian authored and dvyukov committed May 10, 2019
1 parent 24b3a97 commit e3eb428
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion go-fuzz-build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,15 @@ func (c *Context) loadPkg(pkg string) {
cfg.ParseFile = func(fset *token.FileSet, filename string, src []byte) (*ast.File, error) {
return parser.ParseFile(fset, filename, src, parser.ParseComments)
}
initial, err := packages.Load(cfg, pkg, "github.com/dvyukov/go-fuzz/go-fuzz-dep")
// We need to load:
// * the target package, obviously
// * go-fuzz-dep, since we use it for instrumentation
// * reflect, if we are using libfuzzer, since its generated main function requires it
loadpkgs := []string{pkg, "github.com/dvyukov/go-fuzz/go-fuzz-dep"}
if *flagLibFuzzer {
loadpkgs = append(loadpkgs, "reflect")
}
initial, err := packages.Load(cfg, loadpkgs...)
if err != nil {
c.failf("could not load packages: %v", err)
}
Expand Down

0 comments on commit e3eb428

Please sign in to comment.