-
Notifications
You must be signed in to change notification settings - Fork 113
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
6 changed files
with
258 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Add storage backend fuzzing. | ||
|
||
Based on the work done for consensus fuzzing, support was added to run fuzzing | ||
jobs on the storage api backend. |
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,62 @@ | ||
// +build gofuzz | ||
|
||
package fuzz | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
|
||
"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" | ||
"github.com/oasislabs/oasis-core/go/storage/api" | ||
) | ||
|
||
const ( | ||
dataDir string = "/tmp/oasis-node-fuzz-storage" | ||
identityDir string = dataDir + "/identity" | ||
) | ||
|
||
var ( | ||
storageBackend api.Backend | ||
|
||
fuzzer *commonFuzz.InterfaceFuzzer | ||
) | ||
|
||
func init() { | ||
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) | ||
} | ||
|
||
// Create the storage backend service. | ||
storageBackend, err = storage.New(context.Background(), localDB, identity, nil, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create and prepare the fuzzer. | ||
fuzzer = commonFuzz.NewInterfaceFuzzer(storageBackend) | ||
fuzzer.IgnoreMethodNames([]string{ | ||
"Cleanup", | ||
"Initialized", | ||
}) | ||
} | ||
|
||
func Fuzz(data []byte) int { | ||
<-storageBackend.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) | ||
} | ||
} | ||
} |