forked from gortc/sdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdp_fuzz.go
50 lines (40 loc) · 875 Bytes
/
sdp_fuzz.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
// +build gofuzz
package sdp
import "fmt"
// Instructions
// 0. Create a folder called 'corpus' with the contents of the 'testdata' folder
// 1. Get
// go get -u github.com/dvyukov/go-fuzz/...
// 2. Build
// go-fuzz-build github.com/gortc/sdp
// 3. Run
// go-fuzz --bin=sdp-fuzz.zip --workdir=fuzz
func Fuzz(data []byte) int {
s, err := DecodeSession(data, nil)
if err != nil {
return 0
}
m := new(Message)
decoder := NewDecoder(s)
if err := decoder.Decode(m); err != nil {
return 0
}
s2 := make(Session, 0, 100)
s2 = m.Append(s2)
buf := make([]byte, 0, 1024)
buf = s2.AppendTo(buf)
if len(buf) < 2 {
return 0
}
s3, err := DecodeSession(buf, nil)
if err != nil {
return 0
}
if !s3.Equal(s2) {
dbg := make([]byte, 0, 1024)
dbg = s3.AppendTo(dbg)
msg := fmt.Sprintf("Not equal: %q != %q", dbg, buf)
panic(msg)
}
return 1
}