/
gen_initial_corpus.go
110 lines (105 loc) · 2.33 KB
/
gen_initial_corpus.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//go:build !test
// +build !test
package main
import (
"fmt"
"log"
"os"
)
func main() {
tests := []struct {
testNum int
input []byte
wantFail bool
expected interface{}
}{
{
// Proper packet
testNum: 1,
input: []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 19, // Length
4, // Type = Keepalive
},
wantFail: false,
},
{
// Invalid marker
testNum: 2,
input: []byte{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, // Marker
0, 19, // Length
4, // Type = Keepalive
},
wantFail: true,
},
{
// Proper NOTIFICATION packet
testNum: 3,
input: []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 21, // Length
3, // Type = Notification
1, 1, // Message Header Error, Connection Not Synchronized.
},
wantFail: false,
},
{
// Proper OPEN packet
testNum: 4,
input: []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 29, // Length
1, // Type = Open
4, // Version
0, 200, //ASN,
0, 15, // Holdtime
10, 20, 30, 40, // BGP Identifier
0, // Opt Parm Len
},
wantFail: false,
},
{
// Incomplete OPEN packet
testNum: 5,
input: []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 28, // Length
1, // Type = Open
4, // Version
0, 200, //ASN,
0, 15, // Holdtime
0, 0, 0, 100, // BGP Identifier
},
wantFail: true,
},
{
testNum: 6,
input: []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 28, // Length
2, // Type = Update
0, 5, 8, 10, 16, 192, 168, 0, 0, // 2 withdraws
},
wantFail: false,
},
{
testNum: 7,
input: []byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, // Marker
0, 28, // Length
5, // Type = Invalid
0, 5, 8, 10, 16, 192, 168, 0, 0, // Some more stuff
},
wantFail: true,
},
}
for i, t := range tests {
f, err := os.Create(fmt.Sprintf("corpus/%v.bytes", i))
if err != nil {
log.Fatalf(err.Error())
}
f.Write(t.input)
f.Close()
}
}