summaryrefslogtreecommitdiff
path: root/vendor/github.com/pion/dtls/v2/fuzz.go
blob: 56c1bf2104207d914f1ed16cc266ec1063a49417 (plain)
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
// +build gofuzz

package dtls

import "fmt"

func partialHeaderMismatch(a, b recordlayer.Header) bool {
	// Ignoring content length for now.
	a.contentLen = b.contentLen
	return a != b
}

func FuzzRecordLayer(data []byte) int {
	var r recordLayer
	if err := r.Unmarshal(data); err != nil {
		return 0
	}
	buf, err := r.Marshal()
	if err != nil {
		return 1
	}
	if len(buf) == 0 {
		panic("zero buff") // nolint
	}
	var nr recordLayer
	if err = nr.Unmarshal(data); err != nil {
		panic(err) // nolint
	}
	if partialHeaderMismatch(nr.recordlayer.Header, r.recordlayer.Header) {
		panic( // nolint
			fmt.Sprintf("header mismatch: %+v != %+v",
				nr.recordlayer.Header, r.recordlayer.Header,
			),
		)
	}

	return 1
}