-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfuzz_test.go
48 lines (42 loc) · 1.1 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
package dns
import (
"testing"
"golang.org/x/net/dns/dnsmessage"
)
func Fuzz_parsing(f *testing.F) {
f.Add("", "")
f.Add("000000000000", "000000000000")
f.Add("000000000000", "010000000000")
f.Add("000000000000", "00\x80000000000")
f.Add("00\x00000000000", "00\x80000000000")
f.Add("00\x00000000000", "00\x80100000000")
f.Fuzz(func(t *testing.T, req string, res string) {
var parser dnsmessage.Parser
invalid := invalid(req, res)
hreq, ereq := parser.Start([]byte(req))
hres, eres := parser.Start([]byte(res))
if !invalid {
if ereq != nil || eres != nil { // header size
t.Fail()
}
if hreq.ID != hres.ID { // IDs match
t.Fail()
}
if hreq.Response || !hres.Response { // query, response
t.Fail()
}
if hreq.OpCode != 0 || hres.OpCode != 0 { // standard query
t.Fail()
}
if hreq.Truncated || hres.Truncated { // not truncated
t.Fail()
}
if hres.RCode != 0 && hres.RCode != dnsmessage.RCodeNameError { // no error, or name error
t.Fail()
}
if nameError(res) != (hres.RCode == dnsmessage.RCodeNameError) { // name error
t.Fail()
}
}
})
}