From af52ee3b9bba7ddd3c4b33cd7432ed49fa4ff4a4 Mon Sep 17 00:00:00 2001
From: Christoph Petrausch <christoph.petrausch@inovex.de>
Date: Fri, 20 Jul 2018 18:51:30 +0200
Subject: [PATCH] Updated fuzzing code

---
 fuzzing/packet/.gitignore       |  2 ++
 protocols/bgp/packet/fuzzing.go | 40 ++++++++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/fuzzing/packet/.gitignore b/fuzzing/packet/.gitignore
index 818d7868..caa15264 100644
--- a/fuzzing/packet/.gitignore
+++ b/fuzzing/packet/.gitignore
@@ -1 +1,3 @@
 packet-fuzz.zip
+crashers
+suppressions
diff --git a/protocols/bgp/packet/fuzzing.go b/protocols/bgp/packet/fuzzing.go
index 7428662d..0adaded0 100644
--- a/protocols/bgp/packet/fuzzing.go
+++ b/protocols/bgp/packet/fuzzing.go
@@ -1,8 +1,13 @@
-// +build gofuzz
+// foobar
+// +bu ild go fuzz
 
 package packet
 
-import "bytes"
+import (
+	"bytes"
+
+	"github.com/bio-routing/bio-rd/protocols/bgp/types"
+)
 
 const (
 	INC_PRIO = 1
@@ -13,13 +18,32 @@ const (
 func Fuzz(data []byte) int {
 
 	buf := bytes.NewBuffer(data)
-	msg, err := Decode(buf)
-	if err != nil {
-		if msg != nil {
-			panic("msg != nil on error")
+	for _, option := range getAllOptions() {
+		msg, err := Decode(buf, &option)
+		if err != nil {
+			if msg != nil {
+				panic("msg != nil on error")
+			}
+
 		}
-		return KEEP
+		return INC_PRIO
 	}
+	return KEEP
+}
 
-	return INC_PRIO
+func getAllOptions() []types.Options {
+	parameters := []bool{true, false}
+	var ret []types.Options
+	for _, octet := range parameters {
+		for _, multi := range parameters {
+			for _, addPathX := range parameters {
+				ret = append(ret, types.Options{
+					Supports4OctetASN:     octet,
+					SupportsMultiProtocol: multi,
+					AddPathRX:             addPathX,
+				})
+			}
+		}
+	}
+	return ret
 }
-- 
GitLab