3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

Merge pull request #1023 from slingamn/issue1021_modeparam

fix #1021
This commit is contained in:
Shivaram Lingamneni 2020-05-18 00:58:35 -07:00 committed by GitHub
commit aa79706165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View File

@ -564,7 +564,12 @@ func (channel *Channel) hasClient(client *Client) bool {
// <mode> <mode params>
func (channel *Channel) modeStrings(client *Client) (result []string) {
isMember := client.HasMode(modes.Operator) || channel.hasClient(client)
hasPrivs := client.HasMode(modes.Operator)
channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock()
isMember := hasPrivs || channel.members[client] != nil
showKey := isMember && (channel.key != "")
showUserLimit := channel.userLimit > 0
@ -580,9 +585,6 @@ func (channel *Channel) modeStrings(client *Client) (result []string) {
mods += channel.flags.String()
channel.stateMutex.RLock()
defer channel.stateMutex.RUnlock()
result = []string{mods}
// args for flags with args: The order must match above to keep

View File

@ -134,6 +134,15 @@ func ParseDefaultUserModes(rawModes *string) modes.ModeChanges {
return modeChanges
}
// #1021: channel key must be valid as a non-final parameter
func validateChannelKey(key string) bool {
// empty string is valid in this context because it unsets the mode
if len(key) == 0 {
return true
}
return key[0] != ':' && strings.IndexByte(key, ' ') == -1
}
// ApplyChannelModeChanges applies a given set of mode changes.
func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, changes modes.ModeChanges, rb *ResponseBuffer) (applied modes.ModeChanges) {
// so we only output one warning for each list type when full
@ -244,8 +253,12 @@ func (channel *Channel) ApplyChannelModeChanges(client *Client, isSamode bool, c
case modes.Key:
switch change.Op {
case modes.Add:
if validateChannelKey(change.Arg) {
channel.setKey(change.Arg)
applied = append(applied, change)
} else {
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))
}
case modes.Remove:
channel.setKey("")
applied = append(applied, change)