This repository has been archived by the owner on Jun 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
fuzz_test.go
96 lines (84 loc) · 1.79 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// +build gofuzz
package stun
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestMessageType_FuzzerCrash1(t *testing.T) {
input := []byte("\x9c\xbe\x03")
FuzzType(input)
}
func TestMessageCrash2(t *testing.T) {
input := []byte("00\x00\x000000000000000000")
FuzzMessage(input)
}
func corpus(t *testing.T, function, typ string) [][]byte {
var data [][]byte
p := filepath.Join("fuzz", function, typ)
f, err := os.Open(p)
if err != nil {
if os.IsNotExist(err) {
t.Skip("does not exist")
}
t.Fatal(err)
}
list, err := f.Readdir(-1)
if err != nil {
t.Fatal(err)
}
for _, d := range list {
if strings.Contains(d.Name(), ".") {
// Skipping non-raw files.
continue
}
df, err := os.Open(filepath.Join(p, d.Name()))
if err != nil {
t.Fatal(err)
}
buf := make([]byte, 5000)
n, _ := df.Read(buf)
data = append(data, buf[:n])
df.Close()
}
return data
}
func TestFuzzMessage_Coverage(t *testing.T) {
for _, buf := range corpus(t, "stun-msg", "corpus") {
FuzzMessage(buf)
}
}
func TestFuzzMessage_Crashers(t *testing.T) {
for _, buf := range corpus(t, "stun-msg", "crashers") {
FuzzMessage(buf)
}
}
func TestFuzzType_Coverage(t *testing.T) {
for _, buf := range corpus(t, "stun-typ", "corpus") {
FuzzType(buf)
}
}
func TestFuzzType_Crashers(t *testing.T) {
for _, buf := range corpus(t, "stun-typ", "crashers") {
FuzzType(buf)
}
}
func TestAttrPick(t *testing.T) {
attributes := attrs{
{new(XORMappedAddress), AttrXORMappedAddress},
}
for i := byte(0); i < 255; i++ {
attributes.pick(i)
}
}
func TestFuzzSetters_Crashers(t *testing.T) {
for _, buf := range corpus(t, "stun-setters", "crashers") {
FuzzSetters(buf)
}
}
func TestFuzzSetters_Coverage(t *testing.T) {
for _, buf := range corpus(t, "stun-setters", "corpus") {
FuzzSetters(buf)
}
}