mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 03:49:27 +01:00
Eph. memory catches invalid target (hi.s. delete)
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)
This commit is contained in:
parent
f6f7315458
commit
f8cd8469ad
@ -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
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
|
||||
var (
|
||||
ErrDisallowed = errors.New("disallowed")
|
||||
ErrDBIsNil = errors.New("db == nil")
|
||||
)
|
||||
|
||||
const (
|
||||
@ -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())
|
||||
|
@ -6,6 +6,7 @@
|
||||
package irc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user