Browse Source

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)
pull/2024/head
William Rehwinkel 1 year ago
parent
commit
f8cd8469ad
No account linked to committer's email address
3 changed files with 13 additions and 1 deletions
  1. 1
    0
      irc/errors.go
  2. 2
    1
      irc/mysql/history.go
  3. 10
    0
      irc/server.go

+ 1
- 0
irc/errors.go View File

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

+ 2
- 1
irc/mysql/history.go View File

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

+ 10
- 0
irc/server.go View File

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

Loading…
Cancel
Save