From 2155f245b7c21a981be1fc25bfcd0deaed917038 Mon Sep 17 00:00:00 2001 From: Martin/Geno Date: Thu, 6 Sep 2018 13:42:06 +0200 Subject: [PATCH] [BUGFIX] do not crash on invalid input --- bot/command.go | 8 ++++++++ database/notify.go | 3 +++ 2 files changed, 11 insertions(+) diff --git a/bot/command.go b/bot/command.go index 119b9a8..6f74480 100644 --- a/bot/command.go +++ b/bot/command.go @@ -34,10 +34,18 @@ func (b *Bot) addSend(answer func(string), from string, params []string) { if h == nil { h = b.db.NewHost(host) } + if h == nil { + answer(fmt.Sprintf("could not create host %s", host)) + return + } n, ok := b.db.NotifiesByAddress[to] if !ok { n = b.db.NewNotify(to) } + if n == nil { + answer(fmt.Sprintf("could not create notify %s in list of %s", to, host)) + return + } h.AddNotify(n) answer(fmt.Sprintf("added %s in list of %s", to, host)) diff --git a/database/notify.go b/database/notify.go index d614fec..22fc748 100644 --- a/database/notify.go +++ b/database/notify.go @@ -86,6 +86,9 @@ func (db *DB) AddNotify(n *Notify) { func (db *DB) NewNotify(to string) *Notify { addr := strings.Split(to, ":") + if len(addr) != 2 { + return nil + } n := &Notify{ Protocol: addr[0], To: addr[1],