-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathfuzz_test.go
45 lines (36 loc) · 1.02 KB
/
fuzz_test.go
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
//go:build go1.18
// +build go1.18
// Fuzzing test(s) are gated behind build tags in order to avoid generating errors
// when running on versions of Go that do not support fuzzing. This was added in
// Go 1.18.
package ber
import (
"os"
"testing"
"time"
)
func FuzzDecodePacket(f *testing.F) {
// Seed the fuzz corpus with the test cases defined in suite_test.go
for _, tc := range testCases {
file := tc.File
dataIn, err := os.ReadFile(file)
if err != nil {
f.Fatalf("failed to load file %s into fuzz corpus: %v", file, err)
continue
}
f.Add(dataIn)
}
// Seed the fuzz corpus with data known to cause panics in the past
f.Add([]byte{0x09, 0x02, 0x85, 0x30})
f.Add([]byte{0x09, 0x01, 0xcf})
f.Fuzz(func(t *testing.T, data []byte) {
stime := time.Now()
p, err := DecodePacketErr(data)
if e := time.Since(stime); e > (time.Millisecond * 500) {
t.Fatalf("DecodePacketErr took too long: %s", e)
}
if p == nil && err == nil {
t.Fatalf("DecodePacketErr returned a nil packet and no error")
}
})
}