[BUGFIX] do not crash on invalid input

This commit is contained in:
Martin/Geno 2018-09-06 13:42:06 +02:00
parent 1a129edd21
commit 2155f245b7
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 11 additions and 0 deletions

View File

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

View File

@ -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],