Browse Source

Merge pull request #1023 from slingamn/issue1021_modeparam

fix #1021
tags/v2.1.0-rc1
Shivaram Lingamneni 4 years ago
parent
commit
aa79706165
No account linked to committer's email address
2 changed files with 21 additions and 6 deletions
  1. 6
    4
      irc/channel.go
  2. 15
    2
      irc/modes.go

+ 6
- 4
irc/channel.go View File

564
 
564
 
565
 // <mode> <mode params>
565
 // <mode> <mode params>
566
 func (channel *Channel) modeStrings(client *Client) (result []string) {
566
 func (channel *Channel) modeStrings(client *Client) (result []string) {
567
-	isMember := client.HasMode(modes.Operator) || channel.hasClient(client)
567
+	hasPrivs := client.HasMode(modes.Operator)
568
+
569
+	channel.stateMutex.RLock()
570
+	defer channel.stateMutex.RUnlock()
571
+
572
+	isMember := hasPrivs || channel.members[client] != nil
568
 	showKey := isMember && (channel.key != "")
573
 	showKey := isMember && (channel.key != "")
569
 	showUserLimit := channel.userLimit > 0
574
 	showUserLimit := channel.userLimit > 0
570
 
575
 
580
 
585
 
581
 	mods += channel.flags.String()
586
 	mods += channel.flags.String()
582
 
587
 
583
-	channel.stateMutex.RLock()
584
-	defer channel.stateMutex.RUnlock()
585
-
586
 	result = []string{mods}
588
 	result = []string{mods}
587
 
589
 
588
 	// args for flags with args: The order must match above to keep
590
 	// args for flags with args: The order must match above to keep

+ 15
- 2
irc/modes.go View File

134
 	return modeChanges
134
 	return modeChanges
135
 }
135
 }
136
 
136
 
137
+// #1021: channel key must be valid as a non-final parameter
138
+func validateChannelKey(key string) bool {
139
+	// empty string is valid in this context because it unsets the mode
140
+	if len(key) == 0 {
141
+		return true
142
+	}
143
+	return key[0] != ':' && strings.IndexByte(key, ' ') == -1
144
+}
145
+
137
 // ApplyChannelModeChanges applies a given set of mode changes.
146
 // ApplyChannelModeChanges applies a given set of mode changes.
138
 func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, changes modes.ModeChanges, rb *ResponseBuffer) (applied modes.ModeChanges) {
147
 func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, changes modes.ModeChanges, rb *ResponseBuffer) (applied modes.ModeChanges) {
139
 	// so we only output one warning for each list type when full
148
 	// so we only output one warning for each list type when full
244
 		case modes.Key:
253
 		case modes.Key:
245
 			switch change.Op {
254
 			switch change.Op {
246
 			case modes.Add:
255
 			case modes.Add:
247
-				channel.setKey(change.Arg)
248
-				applied = append(applied, change)
256
+				if validateChannelKey(change.Arg) {
257
+					channel.setKey(change.Arg)
258
+					applied = append(applied, change)
259
+				} else {
260
+					rb.Add(nil, client.server.name, ERR_INVALIDMODEPARAM, details.nick, "*", fmt.Sprintf(client.t("Invalid mode %[1]s parameter: %[2]s"), string(change.Mode), change.Arg))
261
+				}
249
 			case modes.Remove:
262
 			case modes.Remove:
250
 				channel.setKey("")
263
 				channel.setKey("")
251
 				applied = append(applied, change)
264
 				applied = append(applied, change)

Loading…
Cancel
Save