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

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

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

+ 10
- 0
irc/server.go View File

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

Loading…
Cancel
Save