forked from free5gc/nas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz_test.go
70 lines (64 loc) · 1.5 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
//go:build go1.18
// +build go1.18
package nas_test
import (
"bytes"
"fmt"
"testing"
"github.com/free5gc/nas"
)
func FuzzNAS(f *testing.F) {
f.Fuzz(func(t *testing.T, d []byte) {
msg := new(nas.Message)
err := msg.PlainNasDecode(&d)
if err == nil {
buf, err := msg.PlainNasEncode()
if err != nil {
panic(fmt.Sprintf("Re-encoding failed: %s", err.Error()))
}
msg2 := new(nas.Message)
err = msg2.PlainNasDecode(&buf)
if err != nil {
panic(fmt.Sprintf("Re-decoding failed: %s", err.Error()))
}
}
})
}
func FuzzGmmMessageDecode(f *testing.F) {
f.Fuzz(func(t *testing.T, d []byte) {
msg := new(nas.Message)
err := msg.GmmMessageDecode(&d)
if err == nil {
buf := new(bytes.Buffer)
err := msg.GmmMessageEncode(buf)
if err != nil {
panic(fmt.Sprintf("Re-encoding failed: %s", err.Error()))
}
msg2 := new(nas.Message)
buf2 := buf.Bytes()
err = msg2.GmmMessageDecode(&buf2)
if err != nil {
panic(fmt.Sprintf("Re-decoding failed: %s", err.Error()))
}
}
})
}
func FuzzGsmMessageDecode(f *testing.F) {
f.Fuzz(func(t *testing.T, d []byte) {
msg := new(nas.Message)
err := msg.GsmMessageDecode(&d)
if err == nil {
buf := new(bytes.Buffer)
err := msg.GsmMessageEncode(buf)
if err != nil {
panic(fmt.Sprintf("Re-encoding failed: %s", err.Error()))
}
msg2 := new(nas.Message)
buf2 := buf.Bytes()
err = msg2.GsmMessageDecode(&buf2)
if err != nil {
panic(fmt.Sprintf("Re-decoding failed: %s", err.Error()))
}
}
})
}