summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
authorAnatole Denis <natolumin@unverle.fr>2019-10-03 19:44:41 +0200
committerAnatole Denis <natolumin@unverle.fr>2019-10-07 12:29:49 +0200
commit998c511a2090c3915d8060d687cb9ec3784fc60b (patch)
tree376946e35dda664eb119f6fc985e7c4e50086492 /dhcpv6
parent651e0846f78086900cc734e93f57e3bc2eca0265 (diff)
dhcpv6: Add a fuzzing entrypoint for go-fuzz
This adds the required function for running [go-fuzz](https://github.com/dvyukov/go-fuzz) on the dhcpv6 library. It tests the following behaviour: * Parsing messages doesn't crash * Parsed messages are identical after being serialized and deserialized Signed-off-by: Anatole Denis <natolumin@unverle.fr>
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/fuzz.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/dhcpv6/fuzz.go b/dhcpv6/fuzz.go
new file mode 100644
index 0000000..3f5afef
--- /dev/null
+++ b/dhcpv6/fuzz.go
@@ -0,0 +1,33 @@
+// +build gofuzz
+
+package dhcpv6
+
+import (
+ "bytes"
+ "fmt"
+)
+
+// Fuzz is an entrypoint for go-fuzz (github.com/dvyukov/go-fuzz)
+func Fuzz(data []byte) int {
+ msg, err := FromBytes(data)
+ if err != nil {
+ return 0
+ }
+
+ serialized := msg.ToBytes()
+ if !bytes.Equal(data, serialized) {
+ rtMsg, err := FromBytes(serialized)
+ fmt.Printf("Input: %x\n", data)
+ fmt.Printf("Round-trip: %x\n", serialized)
+ fmt.Println("Message: ", msg.Summary())
+ fmt.Printf("Go repr: %#v\n", msg)
+ fmt.Println("round-trip reserialized: ", rtMsg.Summary())
+ fmt.Printf("Go repr: %#v\n", rtMsg)
+ if err != nil {
+ fmt.Printf("failed to parse after deserialize-serialize: %v\n", err)
+ }
+ panic("round-trip different")
+ }
+
+ return 1
+}