diff --git a/irc/errors.go b/irc/errors.go index 6c3a790a..56a014a8 100644 --- a/irc/errors.go +++ b/irc/errors.go @@ -56,6 +56,7 @@ var ( errConfusableIdentifier = errors.New("This identifier is confusable with one already in use") errInsufficientPrivs = errors.New("Insufficient privileges") errInvalidUsername = errors.New("Invalid username") + errInvalidTarget = errors.New("Invalid target") errFeatureDisabled = errors.New(`That feature is disabled`) errBanned = errors.New("IP or nickmask banned") errInvalidParams = utils.ErrInvalidParams diff --git a/irc/mysql/history.go b/irc/mysql/history.go index 5f9eff10..f9b2f912 100644 --- a/irc/mysql/history.go +++ b/irc/mysql/history.go @@ -25,6 +25,7 @@ import ( var ( ErrDisallowed = errors.New("disallowed") + ErrDBIsNil = errors.New("db == nil") ) const ( @@ -727,7 +728,7 @@ func (mysql *MySQL) AddDirectMessage(sender, senderAccount, recipient, recipient // note that accountName is the unfolded name func (mysql *MySQL) DeleteMsgid(msgid, accountName string) (err error) { if mysql.db == nil { - return nil + return ErrDBIsNil } ctx, cancel := context.WithTimeout(context.Background(), mysql.getTimeout()) diff --git a/irc/server.go b/irc/server.go index d1cf736e..a27eff31 100644 --- a/irc/server.go +++ b/irc/server.go @@ -6,6 +6,7 @@ package irc import ( + "errors" "fmt" "net" "net/http" @@ -1228,6 +1229,15 @@ func (server *Server) DeleteMessage(target, msgid, accountName string) (err erro if hist == nil { err = server.historyDB.DeleteMsgid(msgid, accountName) + if err != nil && errors.Is(err, mysql.ErrDBIsNil) { + /* + hist == nil, and db == nil. We know that the + target was not either a current channel or + client, and persistent storage is not used. + So this is an invalid target. (see #2020) + */ + return errInvalidTarget + } } else { count := hist.Delete(func(item *history.Item) bool { return item.Message.Msgid == msgid && (accountName == "*" || item.AccountName == accountName)