From 3f51dd25c77626365378f0e07cec120631d8bbc4 Mon Sep 17 00:00:00 2001 From: Thomas Jager Date: Fri, 31 Jul 2015 21:33:36 +0200 Subject: [PATCH] Move fuzzing code to seperate file --- irc.go | 16 +++------------- irc_test_fuzz.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 irc_test_fuzz.go diff --git a/irc.go b/irc.go index ec708fa..576a9b0 100644 --- a/irc.go +++ b/irc.go @@ -86,18 +86,6 @@ func (irc *Connection) readLoop() { return } -// +build gofuzz -func Fuzz(data []byte) int { - b := bytes.NewBuffer(data) - event, err := parseToEvent(b.String()) - if err == nil { - irc := IRC("go-eventirc", "go-eventirc") - irc.RunCallbacks(event) - return 1 - } - return 0 -} - //Parse raw irc messages func parseToEvent(msg string) (*Event, error) { msg = strings.TrimSuffix(msg, "\n") //Remove \r\n @@ -362,7 +350,9 @@ func (irc *Connection) Disconnect() { } irc.Wait() - irc.socket.Close() + if irc.socket != nil { + irc.socket.Close() + } irc.socket = nil irc.ErrorChan() <- ErrDisconnected } diff --git a/irc_test_fuzz.go b/irc_test_fuzz.go new file mode 100644 index 0000000..82202e1 --- /dev/null +++ b/irc_test_fuzz.go @@ -0,0 +1,14 @@ +// +build gofuzz + +package irc + +func Fuzz(data []byte) int { + b := bytes.NewBuffer(data) + event, err := parseToEvent(b.String()) + if err == nil { + irc := IRC("go-eventirc", "go-eventirc") + irc.RunCallbacks(event) + return 1 + } + return 0 +}