3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 11:59:40 +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:
William Rehwinkel 2022-12-25 16:53:17 -05:00
parent f6f7315458
commit f8cd8469ad
No known key found for this signature in database
GPG Key ID: 55FE8F99DD713D20
3 changed files with 13 additions and 1 deletions

View File

@ -54,6 +54,7 @@ var (
errConfusableIdentifier = errors.New("This identifier is confusable with one already in use") errConfusableIdentifier = errors.New("This identifier is confusable with one already in use")
errInsufficientPrivs = errors.New("Insufficient privileges") errInsufficientPrivs = errors.New("Insufficient privileges")
errInvalidUsername = errors.New("Invalid username") errInvalidUsername = errors.New("Invalid username")
errInvalidTarget = errors.New("Invalid target")
errFeatureDisabled = errors.New(`That feature is disabled`) errFeatureDisabled = errors.New(`That feature is disabled`)
errBanned = errors.New("IP or nickmask banned") errBanned = errors.New("IP or nickmask banned")
errInvalidParams = utils.ErrInvalidParams errInvalidParams = utils.ErrInvalidParams

View File

@ -24,6 +24,7 @@ import (
var ( var (
ErrDisallowed = errors.New("disallowed") ErrDisallowed = errors.New("disallowed")
ErrDBIsNil = errors.New("db == nil")
) )
const ( const (
@ -726,7 +727,7 @@ func (mysql *MySQL) AddDirectMessage(sender, senderAccount, recipient, recipient
// note that accountName is the unfolded name // note that accountName is the unfolded name
func (mysql *MySQL) DeleteMsgid(msgid, accountName string) (err error) { func (mysql *MySQL) DeleteMsgid(msgid, accountName string) (err error) {
if mysql.db == nil { if mysql.db == nil {
return nil return ErrDBIsNil
} }
ctx, cancel := context.WithTimeout(context.Background(), mysql.getTimeout()) ctx, cancel := context.WithTimeout(context.Background(), mysql.getTimeout())

View File

@ -6,6 +6,7 @@
package irc package irc
import ( import (
"errors"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -1074,6 +1075,15 @@ func (server *Server) DeleteMessage(target, msgid, accountName string) (err erro
if hist == nil { if hist == nil {
err = server.historyDB.DeleteMsgid(msgid, accountName) 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 { } else {
count := hist.Delete(func(item *history.Item) bool { count := hist.Delete(func(item *history.Item) bool {
return item.Message.Msgid == msgid && (accountName == "*" || item.AccountName == accountName) return item.Message.Msgid == msgid && (accountName == "*" || item.AccountName == accountName)