Skip to content

Commit f8cd846

Browse files
committed
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)
1 parent f6f7315 commit f8cd846

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

irc/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var (
5454
errConfusableIdentifier = errors.New("This identifier is confusable with one already in use")
5555
errInsufficientPrivs = errors.New("Insufficient privileges")
5656
errInvalidUsername = errors.New("Invalid username")
57+
errInvalidTarget = errors.New("Invalid target")
5758
errFeatureDisabled = errors.New(`That feature is disabled`)
5859
errBanned = errors.New("IP or nickmask banned")
5960
errInvalidParams = utils.ErrInvalidParams

irc/mysql/history.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
var (
2626
ErrDisallowed = errors.New("disallowed")
27+
ErrDBIsNil = errors.New("db == nil")
2728
)
2829

2930
const (
@@ -726,7 +727,7 @@ func (mysql *MySQL) AddDirectMessage(sender, senderAccount, recipient, recipient
726727
// note that accountName is the unfolded name
727728
func (mysql *MySQL) DeleteMsgid(msgid, accountName string) (err error) {
728729
if mysql.db == nil {
729-
return nil
730+
return ErrDBIsNil
730731
}
731732

732733
ctx, cancel := context.WithTimeout(context.Background(), mysql.getTimeout())

irc/server.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package irc
77

88
import (
9+
"errors"
910
"fmt"
1011
"net"
1112
"net/http"
@@ -1074,6 +1075,15 @@ func (server *Server) DeleteMessage(target, msgid, accountName string) (err erro
10741075

10751076
if hist == nil {
10761077
err = server.historyDB.DeleteMsgid(msgid, accountName)
1078+
if err != nil && errors.Is(err, mysql.ErrDBIsNil) {
1079+
/*
1080+
hist == nil, and db == nil. We know that the
1081+
target was not either a current channel or
1082+
client, and persistent storage is not used.
1083+
So this is an invalid target. (see #2020)
1084+
*/
1085+
return errInvalidTarget
1086+
}
10771087
} else {
10781088
count := hist.Delete(func(item *history.Item) bool {
10791089
return item.Message.Msgid == msgid && (accountName == "*" || item.AccountName == accountName)

0 commit comments

Comments
 (0)