Skip to content

Commit

Permalink
modules support: adjust wording based on first-pass review, and updat…
Browse files Browse the repository at this point in the history
…e vendor test (#3)

* travis: attempt to install cmd/testscript

* testing: initial check of 'go-fuzz-build -h' output to see if any testscripts work

* testing: change name of first test script

* travis: check if the 'testscript' cmd seems to function at all.

* testing: use the exec command to invoke 'go-fuzz-build -h'

* testing: create initially failing test case for v2 modules

* travis: run testscript for v2 modules

* testing: remember to use 'exec' to invoke go-fuzz-build

* testing: adjust comments in v2 module testscript

* go-fuzz-build: preliminary module support

* testing: flip  from an expected failure to an expected pass for a module test

* go-fuzz-build: update comments for preliminary modules support

* go-fuzz: preliminary modules support for go-fuzz itself

* travis: go-fuzz-defs sanity check

* travis: additional temp sanity check

* travis: add more comments, some additional sanity checks in case we need to debug in future

* travis: s/go-fuzz-deps/go-fuzz-dep/

* testing: validate behavior of v2 modules

* testing: renamed fuzz_help.txt

* testing: update travis to use the renamed testscripts

* travis: conditionally set GO111MODULE=auto, and test Go 1.13 rather than 1.11

* testing: validate modules outside GOPATH

* testing: validate modules inside GOPATH

* testing: invoke timeout properly

* testing: preliminary test for vendored modules (not yet supported)

* testing: validate how go-fuzz-dep and go-fuzz-defs are found

* travis: run the latest testscripts for modules testing

* testing: fix typo in mod_outside_gopath.txt file name

* travis: fix typo in file name

* go-fuzz-build: detect -mod=vendor

* testing: validate we get a proper error for -mod=vendor

* readme: describe preliminary modules support

* readme: correct typo in modules support

* readme: adjust modules support section

* readme: tweak wording based on PR review

* go-fuzz: tweak comment wording by removing "preliminary modules support"

* go-fuzz-build: tweak comment wording by removing "preliminary modules support"

* mod_vendor.txt: avoid triggering Go 1.14 auto detection of a vendor directory
  • Loading branch information
thepudds authored Oct 20, 2019
1 parent f6aba75 commit e55f0a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ You must have a `require` directive for `github.com/dvyukov/go-fuzz` in your go.

1. Prior to invoking go-fuzz-build, add a `require` for `github.com/dvyukov/go-fuzz` in your go.mod. A common approach for tracking tool dependencies like this is [via a tools.go file](https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module). Alternatively, you could for example manually add `require github.com/dvyukov/go-fuzz latest` to your go.mod.

2. If you do not have a `require` for `github.com/dvyukov/go-fuzz` in your go.mod, go-fuzz-build will add one automatically. If desired, you can revert your go.mod file when you are done.
2. If you do not have a `require` for `github.com/dvyukov/go-fuzz` in your go.mod, go-fuzz-build will add one automatically. If desired, you can revert your go.mod file when go-fuzz-build is done.

Vendoring with modules is not yet supported. A `vendor` directory will be ignored, and go-fuzz will report an error if `GOFLAGS=-mod=vendor` is set.

Note that while modules are used to prepare the build, the final instrumented build is still done in GOPATH mode.
For most code, this should not matter.
For most modules, this should not matter.

## libFuzzer support

Expand Down
14 changes: 6 additions & 8 deletions go-fuzz-build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ func makeTags() string {
func basePackagesConfig() *packages.Config {
cfg := new(packages.Config)

// Preliminary modules support: note that we do not set
// GO111MODULE here in order to respect any GO111MODULE setting by the user
// as we are finding dependencies. Note, however, that we are
// still setting up a GOPATH to build, so we later will force
// Note that we do not set GO111MODULE here in order to respect any GO111MODULE
// setting by the user as we are finding dependencies. Note, however, that
// we are still setting up a GOPATH to build, so we later will force
// GO111MODULE to be off when building so that we are in GOPATH mode.
// If the user has not set GO111MODULE, the meaning here is
// left up to cmd/go (defaulting to 'auto' in Go 1.11-1.13,
Expand Down Expand Up @@ -109,7 +108,7 @@ func main() {
c.failf("-race and -libfuzzer are incompatible")
}
if checkModVendor() {
// Preliminary modules support: we don't support -mod=vendor.
// We don't support -mod=vendor with modules.
// Part of the issue is go-fuzz-dep and go-fuzz-defs
// won't be in the user's vendor directory.
c.failf("GOFLAGS with -mod=vendor is not supported")
Expand Down Expand Up @@ -529,9 +528,8 @@ func (c *Context) buildInstrumentedBinary(blocks *[]CoverBlock, sonar *[]CoverBl
args = append(args, "-o", outf, mainPkg)
cmd := exec.Command("go", args...)

// Preliminary modules support: we are constructing a GOPATH
// environment, so while building we force GOPATH mode here
// via GO111MODULE=off.
// We are constructing a GOPATH environment, so while building
// we force GOPATH mode here via GO111MODULE=off.
cmd.Env = append(os.Environ(),
"GOROOT="+filepath.Join(c.workdir, "goroot"),
"GOPATH="+filepath.Join(c.workdir, "gopath"),
Expand Down
5 changes: 2 additions & 3 deletions go-fuzz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ func main() {
// Try the default. Best effort only.
var bin string
cfg := new(packages.Config)
// Preliminary modules support: note that we do not set
// GO111MODULE here in order to respect any GO111MODULE setting by the user
// as we are finding dependencies. See preliminary modules support
// Note that we do not set GO111MODULE here in order to respect any GO111MODULE
// setting by the user as we are finding dependencies. See modules support
// comments in go-fuzz-build/main.go for more details.
cfg.Env = os.Environ()
pkgs, err := packages.Load(cfg, ".")
Expand Down
6 changes: 6 additions & 0 deletions testscripts/mod_vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ rm foo-fuzz.zip
# foo has vendored bar and (in theory) made a code change inside foo's vendor
# directory. The bar code inside foo's vendor compiles, but the original
# bar code does not compile.
# The go.mod files set 'go 1.13' to avoid triggering the Go 1.14 auto
# detection of a vendor directory.

-- foo/fuzz.go --
package foo
Expand All @@ -106,6 +108,8 @@ func FuzzUsingVendor(data []byte) int {
-- foo/go.mod --
module example.com/foo

go 1.13

require (
example.com/bar v0.0.0
github.com/dvyukov/go-fuzz latest
Expand All @@ -131,3 +135,5 @@ func Bar() string {

-- bar/go.mod --
module example.com/bar

go 1.13

0 comments on commit e55f0a1

Please sign in to comment.