Move fuzzing code to seperate file

This commit is contained in:
Thomas Jager 2015-07-31 21:33:36 +02:00
parent f204a14e00
commit 3f51dd25c7
2 changed files with 17 additions and 13 deletions

14
irc.go
View File

@ -86,18 +86,6 @@ func (irc *Connection) readLoop() {
return 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 //Parse raw irc messages
func parseToEvent(msg string) (*Event, error) { func parseToEvent(msg string) (*Event, error) {
msg = strings.TrimSuffix(msg, "\n") //Remove \r\n msg = strings.TrimSuffix(msg, "\n") //Remove \r\n
@ -362,7 +350,9 @@ func (irc *Connection) Disconnect() {
} }
irc.Wait() irc.Wait()
if irc.socket != nil {
irc.socket.Close() irc.socket.Close()
}
irc.socket = nil irc.socket = nil
irc.ErrorChan() <- ErrDisconnected irc.ErrorChan() <- ErrDisconnected
} }

14
irc_test_fuzz.go Normal file
View File

@ -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
}