mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 08:22:26 +08:00
添加 github.com/pion/dtls 代码
This commit is contained in:
38
dtls-2.0.9/fuzz.go
Normal file
38
dtls-2.0.9/fuzz.go
Normal file
@@ -0,0 +1,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
|
||||
}
|
Reference in New Issue
Block a user