Browse Source

Merge f8cd8469ad into 40ceb4956c

pull/2024/merge
William Rehwinkel 3 weeks ago
parent
commit
470e243a9b
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

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

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

@@ -25,6 +25,7 @@ import (
25 25
 
26 26
 var (
27 27
 	ErrDisallowed = errors.New("disallowed")
28
+	ErrDBIsNil    = errors.New("db == nil")
28 29
 )
29 30
 
30 31
 const (
@@ -727,7 +728,7 @@ func (mysql *MySQL) AddDirectMessage(sender, senderAccount, recipient, recipient
727 728
 // note that accountName is the unfolded name
728 729
 func (mysql *MySQL) DeleteMsgid(msgid, accountName string) (err error) {
729 730
 	if mysql.db == nil {
730
-		return nil
731
+		return ErrDBIsNil
731 732
 	}
732 733
 
733 734
 	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"
@@ -1090,6 +1091,15 @@ func (server *Server) DeleteMessage(target, msgid, accountName string) (err erro
1090 1091
 
1091 1092
 	if hist == nil {
1092 1093
 		err = server.historyDB.DeleteMsgid(msgid, accountName)
1094
+		if err != nil && errors.Is(err, mysql.ErrDBIsNil) {
1095
+			/*
1096
+				hist == nil, and db == nil. We know that the
1097
+				target was not either a current channel or
1098
+				client, and persistent storage is not used.
1099
+				So this is an invalid target. (see #2020)
1100
+			*/
1101
+			return errInvalidTarget
1102
+		}
1093 1103
 	} else {
1094 1104
 		count := hist.Delete(func(item *history.Item) bool {
1095 1105
 			return item.Message.Msgid == msgid && (accountName == "*" || item.AccountName == accountName)

Loading…
Cancel
Save