From 5811226760da84957c99f2cec6896c1edee98316 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 16 Apr 2018 13:20:37 +1000 Subject: [PATCH] Only allow valid snomasks to be set --- irc/modes.go | 8 +++++++- irc/sno/constants.go | 14 ++++++++++++++ irc/snomanager.go | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/irc/modes.go b/irc/modes.go index 7cd297f0..375831eb 100644 --- a/irc/modes.go +++ b/irc/modes.go @@ -54,9 +54,15 @@ func (client *Client) applyUserModeChanges(force bool, changes modes.ModeChanges } var masks []sno.Mask if change.Op == modes.Add || change.Op == modes.Remove { + var newArg string for _, char := range change.Arg { - masks = append(masks, sno.Mask(char)) + mask := sno.Mask(char) + if sno.ValidMasks[mask] { + masks = append(masks, mask) + newArg += string(char) + } } + change.Arg = newArg } if change.Op == modes.Add { client.server.snomasks.AddMasks(client, masks...) diff --git a/irc/sno/constants.go b/irc/sno/constants.go index 697348a9..5449962e 100644 --- a/irc/sno/constants.go +++ b/irc/sno/constants.go @@ -35,4 +35,18 @@ var ( LocalAccounts: "ACCOUNT", LocalXline: "XLINE", } + + // ValidMasks contains the snomasks that we support. + ValidMasks = map[Mask]bool{ + LocalAccouncements: true, + LocalConnects: true, + LocalChannels: true, + LocalKills: true, + LocalNicks: true, + LocalOpers: true, + LocalQuits: true, + Stats: true, + LocalAccounts: true, + LocalXline: true, + } ) diff --git a/irc/snomanager.go b/irc/snomanager.go index 848a87e7..38ab8d6c 100644 --- a/irc/snomanager.go +++ b/irc/snomanager.go @@ -27,6 +27,11 @@ func (m *SnoManager) AddMasks(client *Client, masks ...sno.Mask) { defer m.sendListMutex.Unlock() for _, mask := range masks { + // confirm mask is valid + if !sno.ValidMasks[mask] { + continue + } + currentClientList := m.sendLists[mask] if currentClientList == nil {