Skip to content

Commit

Permalink
Fuzzing add seed, new target and remove bloat
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Singh <ajsinghyadav00@gmail.com>
  • Loading branch information
0x34d committed Nov 14, 2023
1 parent c864545 commit 5a75b68
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 36 deletions.
14 changes: 14 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package dtls

import (
"testing"
)

func FuzzUnmarshalBinary(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
deserialized := &State{}
_ = deserialized.UnmarshalBinary(data)
})
}
19 changes: 19 additions & 0 deletions pkg/protocol/extension/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package extension

import "testing"

func FuzzUnmarshal(f *testing.F) {
f.Add([]byte{0x00})
f.Add([]byte{1, 6, 8, 3, 88, 12, 2, 47})
f.Add([]byte{0x0, 0xa, 0x0, 0x4, 0x0, 0x2, 0x0, 0x1d})
f.Add([]byte{0x00, 0x0b, 0x00, 0x02, 0x01, 0x00})
f.Add([]byte{0x00, 0x0d, 0x00, 0x08, 0x00, 0x06, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03})
f.Add([]byte{0x00, 0x0e, 0x00, 0x05, 0x00, 0x02, 0x00, 0x01, 0x00})

f.Fuzz(func(t *testing.T, data []byte) {
_, _ = Unmarshal(data)
})
}
11 changes: 1 addition & 10 deletions pkg/protocol/handshake/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import (
func FuzzDtlsHandshake(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
h := &Handshake{}
if err := h.Unmarshal(data); err != nil {
return
}
buf, err := h.Marshal()
if err != nil {
t.Fatal(err)
}
if len(buf) == 0 {
t.Fatal("Zero buff")
}
_ = h.Unmarshal(data)
})
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
46 changes: 20 additions & 26 deletions pkg/protocol/recordlayer/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,33 @@
package recordlayer

import (
"reflect"
"testing"
)

func headerMismatch(a, b Header) bool {
// Ignoring content length for now.
a.ContentLen = b.ContentLen
return !reflect.DeepEqual(a, b)
}

func FuzzRecordLayer(f *testing.F) {
Data := []byte{
0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x01,
}
f.Add(Data)

f.Fuzz(func(t *testing.T, data []byte) {
var r RecordLayer
if err := r.Unmarshal(data); err != nil {
return
}

buf, err := r.Marshal()
if err != nil {
return
}

if len(buf) == 0 {
t.Fatal("Zero buff")
}
_ = r.Unmarshal(data)
})
}

var nr RecordLayer
if err = nr.Unmarshal(data); err != nil {
t.Fatal(err)
}
func FuzzUnpackDatagram(f *testing.F) {
Datasingle := []byte{
0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x01,
}
Datamulti := []byte{
0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x01, 0x01,
0x14, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x01, 0x01,
}
f.Add(Datasingle)
f.Add(Datamulti)

if headerMismatch(nr.Header, r.Header) {
t.Fatalf("Header mismatch: %+v != %+v", nr.Header, r.Header)
}
f.Fuzz(func(t *testing.T, data []byte) {
_, _ = UnpackDatagram(data)
})
}
Binary file not shown.
1 change: 1 addition & 0 deletions testdata/fuzz/FuzzUnmarshalBinary/TestResumeServer.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
���serializedState��LocalEpochRemoteEpochLocalRandom��RemoteRandom��CipherSuiteIDMasterSecretSequenceNumberSRTPProtectionProfilePeerCertificates��IdentityHintSessionIDLocalConnectionIDRemoteConnectionIDIsClient��[32]uint8��@��[][]uint8������ e&M����K��'����/��kZO6g��MP��I����������} e&M����������@��Cs.=��5Z��{����rg:[����Le����+0y���*��[�\B�GEv�5�ٕ=�u�CwP9�r�48r�y��;k.E

0 comments on commit 5a75b68

Please sign in to comment.