Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server.DeleteMessage catches channel or client==nil #2024

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions irc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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
Expand Down
3 changes: 2 additions & 1 deletion irc/mysql/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

var (
ErrDisallowed = errors.New("disallowed")
ErrDBIsNil = errors.New("db == nil")
)

const (
Expand Down Expand Up @@ -726,7 +727,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())
Expand Down
10 changes: 10 additions & 0 deletions irc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package irc

import (
"errors"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -1074,6 +1075,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)
Expand Down