-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfuzz.go
More file actions
48 lines (43 loc) · 816 Bytes
/
fuzz.go
File metadata and controls
48 lines (43 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// To fuzz-test this package:
//
// $ go get -u github.com/dvyukov/go-fuzz/go-fuzz
// $ go get -u github.com/dvyukov/go-fuzz/go-fuzz-build
// $ cd `go env GOPATH`
// $ go-fuzz-build go.dedis.ch/protobuf
// $ go-fuzz -workdir=workdir -bin protobuf-fuzz.zip
// +build gofuzz
package protobuf
import (
"fmt"
"reflect"
)
type t1 [32]byte
type t2 struct {
X, Y t1
Sl []bool
T3 t3
T3s [3]t3
}
type t3 struct {
I int
F float64
B bool
}
func Fuzz(data []byte) int {
var it1, it2 t2
var err error
if err = Decode(data, &it1); err != nil {
return 0
}
var buf []byte
if buf, err = Encode(it1); err != nil {
return 0
}
if err = Decode(buf, &it2); err != nil {
return 0
}
if !reflect.DeepEqual(it1, it2) {
panic(fmt.Sprintf("round trip not equal %#v %#v", it1, it2))
}
return 1
}