From a6f3e2c748f43ceb191c77524db4f08548bfccb2 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 22 Feb 2021 22:11:18 -0500 Subject: [PATCH] bump irc-go to latest --- go.mod | 2 +- go.sum | 2 ++ .../goshuirc/irc-go/ircmsg/message.go | 34 +++++++++---------- .../github.com/goshuirc/irc-go/ircmsg/tags.go | 11 +++++- vendor/modules.txt | 2 +- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 1d1b2b17..a96a5df1 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/go-sql-driver/mysql v1.5.0 github.com/go-test/deep v1.0.6 // indirect github.com/gorilla/websocket v1.4.2 - github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9 + github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed github.com/onsi/ginkgo v1.12.0 // indirect github.com/onsi/gomega v1.9.0 // indirect github.com/oragono/confusables v0.0.0-20201108231250-4ab98ab61fb1 diff --git a/go.sum b/go.sum index 24313ebf..00278a1f 100644 --- a/go.sum +++ b/go.sum @@ -36,6 +36,8 @@ github.com/goshuirc/irc-go v0.0.0-20210215162435-14cd697c0c8c h1:pOTMO5A1nszuxNy github.com/goshuirc/irc-go v0.0.0-20210215162435-14cd697c0c8c/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug= github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9 h1:A1mSQ0N5Kx8i+aeqeQ0VLbq3swuH0R/JoQcFcR9yUWA= github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug= +github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed h1:cwwqHrmLafgEucSMC9PmFOA671dc4bEZ5z6FsamnBY8= +github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= diff --git a/vendor/github.com/goshuirc/irc-go/ircmsg/message.go b/vendor/github.com/goshuirc/irc-go/ircmsg/message.go index a195e074..2442d074 100644 --- a/vendor/github.com/goshuirc/irc-go/ircmsg/message.go +++ b/vendor/github.com/goshuirc/irc-go/ircmsg/message.go @@ -9,7 +9,6 @@ import ( "bytes" "errors" "strings" - "unicode/utf8" ) const ( @@ -41,8 +40,8 @@ var ( // (the name references 417 ERR_INPUTTOOLONG; we reserve the right to return it // for messages that exceed the non-tag length limit) ErrorLineTooLong = errors.New("Line could not be parsed because a specified length limit was exceeded") - // ErrorInvalidTagContent indicates that a tag value was invalid - ErrorInvalidTagContent = errors.New("Line could not be parsed because it contained an invalid tag value") + // ErrorInvalidTagContent indicates that a tag name or value was invalid + ErrorInvalidTagContent = errors.New("Line could not be processed because it contained an invalid tag name or value") ErrorCommandMissing = errors.New("IRC messages MUST have a command") ErrorBadParam = errors.New("Cannot have an empty param, a param with spaces, or a param that starts with ':' before the last parameter") @@ -168,19 +167,12 @@ func trimInitialSpaces(str string) string { } func parseLine(line string, maxTagDataLength int, truncateLen int) (ircmsg IRCMessage, err error) { - if strings.IndexByte(line, '\x00') != -1 { - err = ErrorLineContainsBadChar - return - } - - // trim to the first appearance of either '\r' or '\n': - lineEnd := strings.IndexByte(line, '\r') - newlineIndex := strings.IndexByte(line, '\n') - if newlineIndex != -1 && (lineEnd == -1 || newlineIndex < lineEnd) { - lineEnd = newlineIndex - } - if lineEnd != -1 { - line = line[:lineEnd] + // remove either \n or \r\n from the end of the line: + line = strings.TrimSuffix(line, "\n") + line = strings.TrimSuffix(line, "\r") + // now validate for the 3 forbidden bytes: + if strings.IndexByte(line, '\x00') != -1 || strings.IndexByte(line, '\n') != -1 || strings.IndexByte(line, '\r') != -1 { + return ircmsg, ErrorLineContainsBadChar } if len(line) < 1 { @@ -285,8 +277,7 @@ func (ircmsg *IRCMessage) parseTags(tags string) (err error) { // "Implementations [...] MUST NOT perform any validation that would // reject the message if an invalid tag key name is used." if validateTagName(tagName) { - // "Tag values MUST be encoded as UTF8." - if !utf8.ValidString(tagValue) { + if !validateTagValue(tagValue) { return ErrorInvalidTagContent } ircmsg.SetTag(tagName, UnescapeTagValue(tagValue)) @@ -356,10 +347,14 @@ func (ircmsg *IRCMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagD // write the tags, computing the budgets for client-only tags and regular tags var lenRegularTags, lenClientOnlyTags, lenTags int if 0 < len(ircmsg.tags) || 0 < len(ircmsg.clientOnlyTags) { + var tagError error buf.WriteByte('@') firstTag := true writeTags := func(tags map[string]string) { for tag, val := range tags { + if !(validateTagName(tag) && validateTagValue(val)) { + tagError = ErrorInvalidTagContent + } if !firstTag { buf.WriteByte(';') // delimiter } @@ -380,6 +375,9 @@ func (ircmsg *IRCMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagD lenClientOnlyTags -= 1 } buf.WriteByte(' ') + if tagError != nil { + return nil, tagError + } } lenTags = buf.Len() diff --git a/vendor/github.com/goshuirc/irc-go/ircmsg/tags.go b/vendor/github.com/goshuirc/irc-go/ircmsg/tags.go index a48c783a..6d57b00a 100644 --- a/vendor/github.com/goshuirc/irc-go/ircmsg/tags.go +++ b/vendor/github.com/goshuirc/irc-go/ircmsg/tags.go @@ -3,7 +3,10 @@ package ircmsg -import "strings" +import ( + "strings" + "unicode/utf8" +) var ( // valtoescape replaces real characters with message tag escapes. @@ -73,6 +76,7 @@ func UnescapeTagValue(inString string) string { return buf.String() } +// https://ircv3.net/specs/extensions/message-tags.html#rules-for-naming-message-tags func validateTagName(name string) bool { if len(name) == 0 { return false @@ -92,3 +96,8 @@ func validateTagName(name string) bool { } return true } + +// "Tag values MUST be encoded as UTF8." +func validateTagValue(value string) bool { + return utf8.ValidString(value) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index f36b2893..fdcb2ba3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -21,7 +21,7 @@ github.com/go-sql-driver/mysql # github.com/gorilla/websocket v1.4.2 ## explicit github.com/gorilla/websocket -# github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9 +# github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed ## explicit github.com/goshuirc/irc-go/ircfmt github.com/goshuirc/irc-go/ircmsg