Browse Source

validate normalized masks as IRC params

tags/v2.4.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
af2b433195
2 changed files with 12 additions and 2 deletions
  1. 7
    1
      irc/strings.go
  2. 5
    1
      irc/strings_test.go

+ 7
- 1
irc/strings.go View File

@@ -15,6 +15,8 @@ import (
15 15
 	"golang.org/x/text/secure/precis"
16 16
 	"golang.org/x/text/unicode/norm"
17 17
 	"golang.org/x/text/width"
18
+
19
+	"github.com/oragono/oragono/irc/utils"
18 20
 )
19 21
 
20 22
 const (
@@ -270,7 +272,11 @@ func CanonicalizeMaskWildcard(userhost string) (expanded string, err error) {
270 272
 	if host != "*" {
271 273
 		host = strings.ToLower(host)
272 274
 	}
273
-	return fmt.Sprintf("%s!%s@%s", nick, user, host), nil
275
+	expanded = fmt.Sprintf("%s!%s@%s", nick, user, host)
276
+	if utils.SafeErrorParam(expanded) != expanded {
277
+		err = errInvalidCharacter
278
+	}
279
+	return
274 280
 }
275 281
 
276 282
 func foldASCII(str string) (result string, err error) {

+ 5
- 1
irc/strings_test.go View File

@@ -193,7 +193,7 @@ func TestSkeleton(t *testing.T) {
193 193
 func TestCanonicalizeMaskWildcard(t *testing.T) {
194 194
 	tester := func(input, expected string, expectedErr error) {
195 195
 		out, err := CanonicalizeMaskWildcard(input)
196
-		if out != expected {
196
+		if expectedErr == nil && out != expected {
197 197
 			t.Errorf("expected %s to canonicalize to %s, instead %s", input, expected, out)
198 198
 		}
199 199
 		if err != expectedErr {
@@ -216,6 +216,10 @@ func TestCanonicalizeMaskWildcard(t *testing.T) {
216 216
 	tester("Shivaram*", "shivaram*!*@*", nil)
217 217
 	tester("*SHIVARAM*", "*shivaram*!*@*", nil)
218 218
 	tester("*SHIVARAM*   ", "*shivaram*!*@*", nil)
219
+
220
+	tester(":shivaram", "", errInvalidCharacter)
221
+	tester("shivaram!us er@host", "", errInvalidCharacter)
222
+	tester("shivaram!user@ho st", "", errInvalidCharacter)
219 223
 }
220 224
 
221 225
 func validFoldTester(first, second string, equal bool, folder func(string) (string, error), t *testing.T) {

Loading…
Cancel
Save