summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/dhcpv4_test.go
diff options
context:
space:
mode:
authorPablo Mazzini <pmazzini@gmail.com>2023-07-20 10:36:26 +0100
committerGitHub <noreply@github.com>2023-07-20 10:36:26 +0100
commit5648422c16cd75ffbe2c0c792a11badae15ab5e9 (patch)
tree3bbcda3642c565e7c50501b88621708de0f62789 /dhcpv4/dhcpv4_test.go
parentb20c9ba983dfec6371555e7baa343aabd388b22c (diff)
parentd2077e2392548e0fdf2432013e6b00426fbad5f7 (diff)
Merge pull request #508 from 0x34d/master
[Fuzzing] remove old go-fuzz and use Native Go fuzz
Diffstat (limited to 'dhcpv4/dhcpv4_test.go')
-rw-r--r--dhcpv4/dhcpv4_test.go44
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()
+ })
+}