-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
246 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
corpus/ | ||
crashers/ | ||
suppressions/ | ||
*.zip | ||
gencorpus/gencorpus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// +build gofuzz | ||
|
||
package fuzz | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/oasislabs/oasis-core/go/common/crypto/signature" | ||
"github.com/oasislabs/oasis-core/go/common/crypto/signature/signers/file" | ||
commonFuzz "github.com/oasislabs/oasis-core/go/common/fuzz" | ||
"github.com/oasislabs/oasis-core/go/common/identity" | ||
"github.com/oasislabs/oasis-core/go/storage" | ||
) | ||
|
||
const ( | ||
dataDir string = "/tmp/oasis-node-fuzz-storage" | ||
identityDir string = dataDir + "/identity" | ||
) | ||
|
||
func Fuzz(data []byte) int { | ||
signerFactory := file.NewFactory(identityDir, signature.SignerNode, signature.SignerP2P, signature.SignerConsensus) | ||
identity, err := identity.Load(identityDir, signerFactory) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Every Fuzz invocation should get its own database, | ||
// otherwise the database handles would clash. | ||
localDB, err := ioutil.TempDir(dataDir, "worker") | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer os.RemoveAll(localDB) | ||
|
||
// Create the storage backend service. | ||
storage, err := storage.New(context.Background(), localDB, identity, nil, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer storage.Cleanup() | ||
<-storage.Initialized() | ||
|
||
// Finally, create and run the fuzzer. | ||
fuzzer := commonFuzz.NewInterfaceFuzzer(storage) | ||
fuzzer.IgnoreMethodNames([]string{ | ||
"Cleanup", | ||
"Initialized", | ||
}) | ||
fuzzer.DispatchBlob(data) | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// +build gofuzz | ||
|
||
// Gencorpus implements a simple utility to generate corpus files for the fuzzer. | ||
// It has no command-line options and creates the files in the current working directory. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
|
||
commonFuzz "github.com/oasislabs/oasis-core/go/common/fuzz" | ||
"github.com/oasislabs/oasis-core/go/common/identity" | ||
"github.com/oasislabs/oasis-core/go/storage" | ||
) | ||
|
||
const ( | ||
samplesPerMethod int = 20 | ||
) | ||
|
||
func main() { | ||
storage, err := storage.New(context.Background(), "/tmp/oasis-node-fuzz-storage", &identity.Identity{}, nil, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fuzzer := commonFuzz.NewInterfaceFuzzer(storage) | ||
fuzzer.IgnoreMethodNames([]string{ | ||
"Cleanup", | ||
"Initialized", | ||
}) | ||
|
||
for i := 0; i < samplesPerMethod; i++ { | ||
blobs := fuzzer.MakeSampleBlobs() | ||
for meth := 0; meth < len(blobs); meth++ { | ||
fileName := fmt.Sprintf("%s_%02d.bin", fuzzer.Method(meth).Name, i) | ||
_ = ioutil.WriteFile(fileName, blobs[meth], 0644) | ||
} | ||
} | ||
} |