diff options
author | Arjun Singh <ajsinghyadav00@gmail.com> | 2023-07-19 17:18:25 +0530 |
---|---|---|
committer | Arjun Singh <ajsinghyadav00@gmail.com> | 2023-07-20 14:24:16 +0530 |
commit | d2077e2392548e0fdf2432013e6b00426fbad5f7 (patch) | |
tree | 3bbcda3642c565e7c50501b88621708de0f62789 /dhcpv4/dhcpv4_test.go | |
parent | b20c9ba983dfec6371555e7baa343aabd388b22c (diff) |
[Fuzzing] remove deprecated go-fuzz and use Native Go fuzz
Signed-off-by: Arjun Singh <ajsinghyadav00@gmail.com>
Diffstat (limited to 'dhcpv4/dhcpv4_test.go')
-rw-r--r-- | dhcpv4/dhcpv4_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/dhcpv4/dhcpv4_test.go b/dhcpv4/dhcpv4_test.go index a961f78..95523ab 100644 --- a/dhcpv4/dhcpv4_test.go +++ b/dhcpv4/dhcpv4_test.go @@ -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() + }) +} |