Pārlūkot izejas kodu

validate normalized masks as IRC params

tags/v2.4.0-rc1
Shivaram Lingamneni 3 gadus atpakaļ
vecāks
revīzija
af2b433195
2 mainītis faili ar 12 papildinājumiem un 2 dzēšanām
  1. 7
    1
      irc/strings.go
  2. 5
    1
      irc/strings_test.go

+ 7
- 1
irc/strings.go Parādīt failu

15
 	"golang.org/x/text/secure/precis"
15
 	"golang.org/x/text/secure/precis"
16
 	"golang.org/x/text/unicode/norm"
16
 	"golang.org/x/text/unicode/norm"
17
 	"golang.org/x/text/width"
17
 	"golang.org/x/text/width"
18
+
19
+	"github.com/oragono/oragono/irc/utils"
18
 )
20
 )
19
 
21
 
20
 const (
22
 const (
270
 	if host != "*" {
272
 	if host != "*" {
271
 		host = strings.ToLower(host)
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
 func foldASCII(str string) (result string, err error) {
282
 func foldASCII(str string) (result string, err error) {

+ 5
- 1
irc/strings_test.go Parādīt failu

193
 func TestCanonicalizeMaskWildcard(t *testing.T) {
193
 func TestCanonicalizeMaskWildcard(t *testing.T) {
194
 	tester := func(input, expected string, expectedErr error) {
194
 	tester := func(input, expected string, expectedErr error) {
195
 		out, err := CanonicalizeMaskWildcard(input)
195
 		out, err := CanonicalizeMaskWildcard(input)
196
-		if out != expected {
196
+		if expectedErr == nil && out != expected {
197
 			t.Errorf("expected %s to canonicalize to %s, instead %s", input, expected, out)
197
 			t.Errorf("expected %s to canonicalize to %s, instead %s", input, expected, out)
198
 		}
198
 		}
199
 		if err != expectedErr {
199
 		if err != expectedErr {
216
 	tester("Shivaram*", "shivaram*!*@*", nil)
216
 	tester("Shivaram*", "shivaram*!*@*", nil)
217
 	tester("*SHIVARAM*", "*shivaram*!*@*", nil)
217
 	tester("*SHIVARAM*", "*shivaram*!*@*", nil)
218
 	tester("*SHIVARAM*   ", "*shivaram*!*@*", nil)
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
 func validFoldTester(first, second string, equal bool, folder func(string) (string, error), t *testing.T) {
225
 func validFoldTester(first, second string, equal bool, folder func(string) (string, error), t *testing.T) {

Notiek ielāde…
Atcelt
Saglabāt