Permalink
Browse files

vom: go-fuzz

    
A fuzzer for VOM decoding and documentation on how to use it.
    
For some reason, when compiling with go-fuzz, vdl/type.go needs
this little fix to not break the compilation.

Change-Id: Iff332187b79c3109552037650427d619b1c5a40c
  • Loading branch information...
1 parent c61dbf9 commit 995191130e33d9d74ee6a6d9d2bf4b9413158f11 @jeffallen jeffallen committed with tatatodd Jan 14, 2016
Showing with 39 additions and 4 deletions.
  1. +4 −4 vdl/type.go
  2. +35 −0 vom/fuzz.go
View
@@ -101,12 +101,12 @@ func (k Kind) String() string {
type kindBitMask uint32
-func (kindBitMask *kindBitMask) Set(kind Kind) {
- *kindBitMask |= (1 << kind)
+func (k *kindBitMask) Set(kind Kind) {
+ *k |= (1 << kind)
}
-func (kindBitMask kindBitMask) IsSet(kind Kind) bool {
- return (kindBitMask & (1 << kind)) != 0
+func (k kindBitMask) IsSet(kind Kind) bool {
+ return (k & (1 << kind)) != 0
}
// SplitIdent splits the given identifier into its package path and local name.
View
@@ -0,0 +1,35 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build gofuzz
+
+package vom
+
+// To use go-fuzz:
+//
+// $ go get github.com/dvyukov/go-fuzz/go-fuzz{,-build}
+// $ cd $JIRI_ROOT/release/go/src/v.io/v23/vom
+// $ $JIRI_ROOT/release/go/bin/go-fuzz-build v.io/v23/vom
+// $ $JIRI_ROOT/release/go/bin/go-fuzz -bin vom-fuzz.zip -workdir workdir
+//
+// Inputs resulting in crashes will be in workdir/crashers.
+//
+// go-fuzz will explore the space of possible input faster if
+// you put bigger inputs into workdir/corpus to help it. One way to
+// do this is to hack testDecodeVDL to dump parameter "bin" to a
+// new file on every call, then run "go test" once. With an empty
+// corpus directory, go-fuzz will reverse engineer for itself what
+// valid VOM looks like as it explores the input space looking
+// for inputs that increase coverage. Magic!
+
+import "bytes"
+
+func Fuzz(data []byte) int {
+ var v interface{}
+ d := NewDecoder(bytes.NewReader(data))
+ if err := d.Decode(&v); err != nil {
+ return 0 // failed decode; fuzz is indifferent
+ }
+ return 1 // successful decode; give fuzz priority
+}

0 comments on commit 9951911

Please sign in to comment.