From e447c61c7381dd5dc2f08f33e0ae84b4c1f3ac52 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Thu, 18 Mar 2021 03:49:12 -0400 Subject: [PATCH] fix #1596 All truncation must be made UTF8-safe. --- irc/channel.go | 12 ++++-------- irc/handlers.go | 9 ++++----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index 21326977..4b341e3e 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -13,6 +13,8 @@ import ( "sync" + "github.com/goshuirc/irc-go/ircutils" + "github.com/oragono/oragono/irc/caps" "github.com/oragono/oragono/irc/history" "github.com/oragono/oragono/irc/modes" @@ -1259,10 +1261,7 @@ func (channel *Channel) SetTopic(client *Client, topic string, rb *ResponseBuffe return } - topicLimit := client.server.Config().Limits.TopicLen - if len(topic) > topicLimit { - topic = topic[:topicLimit] - } + topic = ircutils.TruncateUTF8Safe(topic, client.server.Config().Limits.TopicLen) channel.stateMutex.Lock() chname := channel.name @@ -1520,10 +1519,7 @@ func (channel *Channel) Kick(client *Client, target *Client, comment string, rb return } - kicklimit := channel.server.Config().Limits.KickLen - if len(comment) > kicklimit { - comment = comment[:kicklimit] - } + comment = ircutils.TruncateUTF8Safe(comment, channel.server.Config().Limits.KickLen) message := utils.MakeMessage(comment) details := client.Details() diff --git a/irc/handlers.go b/irc/handlers.go index b910e1f1..95a99a1a 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -22,6 +22,9 @@ import ( "github.com/goshuirc/irc-go/ircfmt" "github.com/goshuirc/irc-go/ircmsg" + "github.com/goshuirc/irc-go/ircutils" + "golang.org/x/crypto/bcrypt" + "github.com/oragono/oragono/irc/caps" "github.com/oragono/oragono/irc/custime" "github.com/oragono/oragono/irc/flatip" @@ -30,7 +33,6 @@ import ( "github.com/oragono/oragono/irc/modes" "github.com/oragono/oragono/irc/sno" "github.com/oragono/oragono/irc/utils" - "golang.org/x/crypto/bcrypt" ) // helper function to parse ACC callbacks, e.g., mailto:person@example.com, tel:16505551234 @@ -346,10 +348,7 @@ func awayHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respons if len(msg.Params) > 0 { isAway = true awayMessage = msg.Params[0] - awayLen := server.Config().Limits.AwayLen - if len(awayMessage) > awayLen { - awayMessage = awayMessage[:awayLen] - } + awayMessage = ircutils.TruncateUTF8Safe(awayMessage, server.Config().Limits.AwayLen) } rb.session.SetAway(awayMessage)