Skip to content

Commit

Permalink
Eph. memory catches invalid target (hi.s. delete)
Browse files Browse the repository at this point in the history
If hist == nil and mysql database Delete msgid function returns
ErrDBIsNil, we know that the target does not match any channel or user.
Return invalid target error to operator (see #2020)
  • Loading branch information
FiskFan1999 committed Dec 25, 2022
1 parent f6f7315 commit f8cd846
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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

0 comments on commit f8cd846

Please sign in to comment.