Browse Source

Only allow valid snomasks to be set

tags/v0.12.0
Daniel Oaks 6 years ago
parent
commit
5811226760
3 changed files with 26 additions and 1 deletions
  1. 7
    1
      irc/modes.go
  2. 14
    0
      irc/sno/constants.go
  3. 5
    0
      irc/snomanager.go

+ 7
- 1
irc/modes.go View File

@@ -54,9 +54,15 @@ func (client *Client) applyUserModeChanges(force bool, changes modes.ModeChanges
54 54
 			}
55 55
 			var masks []sno.Mask
56 56
 			if change.Op == modes.Add || change.Op == modes.Remove {
57
+				var newArg string
57 58
 				for _, char := range change.Arg {
58
-					masks = append(masks, sno.Mask(char))
59
+					mask := sno.Mask(char)
60
+					if sno.ValidMasks[mask] {
61
+						masks = append(masks, mask)
62
+						newArg += string(char)
63
+					}
59 64
 				}
65
+				change.Arg = newArg
60 66
 			}
61 67
 			if change.Op == modes.Add {
62 68
 				client.server.snomasks.AddMasks(client, masks...)

+ 14
- 0
irc/sno/constants.go View File

@@ -35,4 +35,18 @@ var (
35 35
 		LocalAccounts:      "ACCOUNT",
36 36
 		LocalXline:         "XLINE",
37 37
 	}
38
+
39
+	// ValidMasks contains the snomasks that we support.
40
+	ValidMasks = map[Mask]bool{
41
+		LocalAccouncements: true,
42
+		LocalConnects:      true,
43
+		LocalChannels:      true,
44
+		LocalKills:         true,
45
+		LocalNicks:         true,
46
+		LocalOpers:         true,
47
+		LocalQuits:         true,
48
+		Stats:              true,
49
+		LocalAccounts:      true,
50
+		LocalXline:         true,
51
+	}
38 52
 )

+ 5
- 0
irc/snomanager.go View File

@@ -27,6 +27,11 @@ func (m *SnoManager) AddMasks(client *Client, masks ...sno.Mask) {
27 27
 	defer m.sendListMutex.Unlock()
28 28
 
29 29
 	for _, mask := range masks {
30
+		// confirm mask is valid
31
+		if !sno.ValidMasks[mask] {
32
+			continue
33
+		}
34
+
30 35
 		currentClientList := m.sendLists[mask]
31 36
 
32 37
 		if currentClientList == nil {

Loading…
Cancel
Save