Skip to content

Commit

Permalink
Merge branch 'master' into ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
pmazzini authored Jul 20, 2023
2 parents ffe6e8d + 5648422 commit 5ed9d78
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 74 deletions.
44 changes: 44 additions & 0 deletions dhcpv4/dhcpv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,47 @@ func Test_withIP(t *testing.T) {
b := buff.Buffer
require.Equal(t, b.Len(), 4, "Testing no of bytes written by writeIP func")
}

func FuzzDHCPv4(f *testing.F) {

data_0 := []byte{
1, // dhcp request
1, // ethernet hw type
6, // hw addr length
3, // hop count
0xaa, 0xbb, 0xcc, 0xdd, // transaction ID, big endian (network)
0, 3, // number of seconds
0, 1, // broadcast
0, 0, 0, 0, // client IP address
0, 0, 0, 0, // your IP address
0, 0, 0, 0, // server IP address
0, 0, 0, 0, // gateway IP address
0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // client MAC address + padding
}

data_1 := []byte{
1, // dhcp request
1, // ethernet hw type
6, // hw addr length
0, // hop count
0xaa, 0xbb, 0xcc, 0xdd, // transaction ID
3, 0, // number of seconds
1, 0, // broadcast
0, 0, 0, 0, // client IP address
0, 0, 0, 0, // your IP address
0, 0, 0, 0, // server IP address
0, 0, 0, 0, // gateway IP address
0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // client MAC address + padding
}

f.Add(data_0)
f.Add(data_1)

f.Fuzz(func(t *testing.T, data []byte) {
msg, err := FromBytes(data)
if err != nil {
return
}
msg.ToBytes()
})
}
41 changes: 0 additions & 41 deletions dhcpv4/fuzz.go

This file was deleted.

36 changes: 36 additions & 0 deletions dhcpv6/dhcpv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,39 @@ func TestGetTransactionIDRelay(t *testing.T) {

// TODO test NewMessageTypeSolicit
// test String and Summary

func FuzzDHCPv6(f *testing.F) {

var relayForwBytesDuidUUID_data = []byte{
0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x26, 0x8a, 0x07, 0xff, 0xfe, 0x56,
0xdc, 0xa4, 0x00, 0x12, 0x00, 0x06, 0x24, 0x8a,
0x07, 0x56, 0xdc, 0xa4, 0x00, 0x09, 0x00, 0x5a,
0x06, 0x7d, 0x9b, 0xca, 0x00, 0x01, 0x00, 0x12,
0x00, 0x04, 0xb7, 0xfd, 0x0a, 0x8c, 0x1b, 0x14,
0x10, 0xaa, 0xeb, 0x0a, 0x5b, 0x3f, 0xe8, 0x9d,
0x0f, 0x56, 0x00, 0x06, 0x00, 0x0a, 0x00, 0x17,
0x00, 0x18, 0x00, 0x17, 0x00, 0x18, 0x00, 0x01,
0x00, 0x08, 0x00, 0x02, 0xff, 0xff, 0x00, 0x03,
0x00, 0x28, 0x07, 0x56, 0xdc, 0xa4, 0x00, 0x00,
0x0e, 0x10, 0x00, 0x00, 0x15, 0x18, 0x00, 0x05,
0x00, 0x18, 0x26, 0x20, 0x01, 0x0d, 0xc0, 0x82,
0x90, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xaf, 0xa0, 0x00, 0x00, 0x1c, 0x20, 0x00, 0x00,
0x1d, 0x4c}

f.Add(relayForwBytesDuidUUID_data)
f.Add([]byte{01, 0xab, 0xcd, 0xef, 0x00, 0x00, 0x00, 0x00})
f.Add([]byte{01, 0xa, 0xb, 0xc, 0x00, 0x00, 0x00, 0x00})
f.Add([]byte("0000\x00\x01\x00\x0e\x00\x01000000000000"))

f.Fuzz(func(t *testing.T, data []byte) {
msg, err := FromBytes(data)
if err != nil {
return
}
msg.ToBytes()
})
}
33 changes: 0 additions & 33 deletions dhcpv6/fuzz.go

This file was deleted.

33 changes: 33 additions & 0 deletions rfc1035label/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,36 @@ func TestNestedCompressedLabel(t *testing.T) {
_, err := FromBytes(data)
require.Error(t, err)
}

func FuzzLabel(f *testing.F) {

f.Add([]byte{0x5, 0xaa, 0xbb})
f.Add([]byte{0x3, 0xaa, 0xbb})

data_0 := []byte{
// slackware.it
9, 's', 'l', 'a', 'c', 'k', 'w', 'a', 'r', 'e',
2, 'i', 't',
0,
// insomniac.slackware.it
9, 'i', 'n', 's', 'o', 'm', 'n', 'i', 'a', 'c',
192, 0,
// mail.systemboot.org
4, 'm', 'a', 'i', 'l',
10, 's', 'y', 's', 't', 'e', 'm', 'b', 'o', 'o', 't',
3, 'o', 'r', 'g',
0,
// systemboot.org
192, 31,
}

f.Add(data_0)

f.Fuzz(func(t *testing.T, data []byte) {
labels, err := FromBytes(data)
if err != nil {
return
}
labels.ToBytes()
})
}

0 comments on commit 5ed9d78

Please sign in to comment.