Browse Source

fix #2002 (#2003)

* fix #2002

`CS AMODE #channel +f nickname` is invalid, but was being accepted
incorrectly.

* simplify logic
tags/v2.11.0-rc1
Shivaram Lingamneni 1 year ago
parent
commit
e20c983b57
No account linked to committer's email address
2 changed files with 19 additions and 1 deletions
  1. 10
    1
      irc/chanserv.go
  2. 9
    0
      irc/utils/types.go

+ 10
- 1
irc/chanserv.go View File

@@ -213,8 +213,17 @@ func csAmodeHandler(service *ircService, server *Server, client *Client, command
213 213
 	}
214 214
 
215 215
 	modeChanges, unknown := modes.ParseChannelModeChanges(params[1:]...)
216
+	invalid := len(unknown) != 0
217
+	// #2002: +f takes an argument but is not a channel-user mode,
218
+	// check for anything valid as a channel mode change that is not valid
219
+	// as an AMODE change
220
+	for _, modeChange := range modeChanges {
221
+		if !utils.SliceContains(modes.ChannelUserModes, modeChange.Mode) {
222
+			invalid = true
223
+		}
224
+	}
216 225
 	var change modes.ModeChange
217
-	if len(modeChanges) > 1 || len(unknown) > 0 {
226
+	if len(modeChanges) > 1 || invalid {
218 227
 		service.Notice(rb, client.t("Invalid mode change"))
219 228
 		return
220 229
 	} else if len(modeChanges) == 1 {

+ 9
- 0
irc/utils/types.go View File

@@ -34,3 +34,12 @@ func ReverseSlice[T any](results []T) {
34 34
 		results[i], results[j] = results[j], results[i]
35 35
 	}
36 36
 }
37
+
38
+func SliceContains[T comparable](slice []T, elem T) (result bool) {
39
+	for _, t := range slice {
40
+		if elem == t {
41
+			return true
42
+		}
43
+	}
44
+	return false
45
+}

Loading…
Cancel
Save