]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] internal/fuzz: make RunFuzzWorker accept CorpusEntry
authorJay Conrod <jayconrod@google.com>
Tue, 9 Feb 2021 15:36:27 +0000 (10:36 -0500)
committerJay Conrod <jayconrod@google.com>
Wed, 10 Feb 2021 18:21:14 +0000 (18:21 +0000)
RunFuzzWorker now accepts a fuzz.CorpusEntry instead of []byte. This
may help us pass structured data in the future.

Change-Id: Idf7754cb890b6a835d887032fd23ade4d0713bcf
Reviewed-on: https://go-review.googlesource.com/c/go/+/290692
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
src/internal/fuzz/worker.go
src/testing/fuzz.go
src/testing/internal/testdeps/deps.go
src/testing/testing.go

index 9a92813f8ca76a7146e7f3e6832c3f8fdb735049..f9284db72958d68fb8c9f4837239d288d1f43db8 100644 (file)
@@ -329,7 +329,7 @@ func (w *worker) stop() error {
 //
 // RunFuzzWorker returns an error if it could not communicate with the
 // coordinator process.
-func RunFuzzWorker(ctx context.Context, fn func([]byte) error) error {
+func RunFuzzWorker(ctx context.Context, fn func(CorpusEntry) error) error {
        comm, err := getWorkerComm()
        if err != nil {
                return err
@@ -386,7 +386,7 @@ type workerServer struct {
 
        // fuzzFn runs the worker's fuzz function on the given input and returns
        // an error if it finds a crasher (the process may also exit or crash).
-       fuzzFn func([]byte) error
+       fuzzFn func(CorpusEntry) error
 }
 
 // serve reads serialized RPC messages on fuzzIn. When serve receives a message,
@@ -463,7 +463,7 @@ func (ws *workerServer) fuzz(ctx context.Context, args fuzzArgs) fuzzResponse {
                        b := mem.valueRef()
                        ws.m.mutate(&b)
                        mem.setValueLen(len(b))
-                       if err := ws.fuzzFn(b); err != nil {
+                       if err := ws.fuzzFn(CorpusEntry{Data: b}); err != nil {
                                return fuzzResponse{Err: err.Error()}
                        }
                        // TODO(jayconrod,katiehockman): return early if we find an
index 7ef47872d087b010d309d023c1bac069cba40b26..196b4cf7abf92c8097dcc12f3c428da553c12953 100644 (file)
@@ -142,7 +142,7 @@ func (f *F) Fuzz(ff interface{}) {
        case f.context.runFuzzWorker != nil:
                // Fuzzing is enabled, and this is a worker process. Follow instructions
                // from the coordinator.
-               err := f.context.runFuzzWorker(func(input []byte) error {
+               err := f.context.runFuzzWorker(func(e corpusEntry) error {
                        t := &T{
                                common: common{
                                        signal: make(chan bool),
@@ -151,7 +151,7 @@ func (f *F) Fuzz(ff interface{}) {
                                },
                                context: newTestContext(1, nil),
                        }
-                       go run(t, input)
+                       go run(t, e.Data)
                        <-t.signal
                        if t.Failed() {
                                return errors.New(string(t.output))
@@ -273,7 +273,7 @@ type fuzzContext struct {
        runMatch          *matcher
        fuzzMatch         *matcher
        coordinateFuzzing func(time.Duration, int, []corpusEntry, string, string) error
-       runFuzzWorker     func(func([]byte) error) error
+       runFuzzWorker     func(func(corpusEntry) error) error
        readCorpus        func(string) ([]corpusEntry, error)
 }
 
index 1333944d5ee113403a63a91ed73d1d8e6063bf67..3160cae7a4ea9c8468e97b73ea9779222c65d0c7 100644 (file)
@@ -132,7 +132,7 @@ func (TestDeps) SetPanicOnExit0(v bool) {
        testlog.SetPanicOnExit0(v)
 }
 
-func (TestDeps) CoordinateFuzzing(timeout time.Duration, parallel int, seed []fuzz.CorpusEntry, corpusDir, cacheDir string) error {
+func (TestDeps) CoordinateFuzzing(timeout time.Duration, parallel int, seed []fuzz.CorpusEntry, corpusDir, cacheDir string) (err error) {
        // Fuzzing may be interrupted with a timeout or if the user presses ^C.
        // In either case, we'll stop worker processes gracefully and save
        // crashers and interesting values.
@@ -143,14 +143,14 @@ func (TestDeps) CoordinateFuzzing(timeout time.Duration, parallel int, seed []fu
        ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
        defer stop()
        defer cancel()
-       err := fuzz.CoordinateFuzzing(ctx, parallel, seed, corpusDir, cacheDir)
+       err = fuzz.CoordinateFuzzing(ctx, parallel, seed, corpusDir, cacheDir)
        if err == ctx.Err() {
                return nil
        }
        return err
 }
 
-func (TestDeps) RunFuzzWorker(fn func([]byte) error) error {
+func (TestDeps) RunFuzzWorker(fn func(fuzz.CorpusEntry) error) error {
        // Worker processes may or may not receive a signal when the user presses ^C
        // On POSIX operating systems, a signal sent to a process group is delivered
        // to all processes in that group. This is not the case on Windows.
index e2abec222486dd4887f706b0dbe4a75986c859cd..72529956c31cb8af209f503a1901f88dfc33a9a1 100644 (file)
@@ -1364,8 +1364,8 @@ func (f matchStringOnly) SetPanicOnExit0(bool)                        {}
 func (f matchStringOnly) CoordinateFuzzing(time.Duration, int, []corpusEntry, string, string) error {
        return errMain
 }
-func (f matchStringOnly) RunFuzzWorker(func([]byte) error) error   { return errMain }
-func (f matchStringOnly) ReadCorpus(string) ([]corpusEntry, error) { return nil, errMain }
+func (f matchStringOnly) RunFuzzWorker(func(corpusEntry) error) error { return errMain }
+func (f matchStringOnly) ReadCorpus(string) ([]corpusEntry, error)    { return nil, errMain }
 
 // Main is an internal function, part of the implementation of the "go test" command.
 // It was exported because it is cross-package and predates "internal" packages.
@@ -1409,7 +1409,7 @@ type testDeps interface {
        StopTestLog() error
        WriteProfileTo(string, io.Writer, int) error
        CoordinateFuzzing(time.Duration, int, []corpusEntry, string, string) error
-       RunFuzzWorker(func([]byte) error) error
+       RunFuzzWorker(func(corpusEntry) error) error
        ReadCorpus(string) ([]corpusEntry, error)
 }