From 7201f14b8bc5fbb890e8ebf6d8cde9ce99016573 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 24 Apr 2022 00:31:20 -0400 Subject: [PATCH 1/2] partial fix for #1933 If the nickname must equal the account name (because always-on or force-nick-equals-account), the correct error response to an empty or otherwise invalid nickname is the usual "You must use your account name as your nickname". --- irc/client_lookup_set.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irc/client_lookup_set.go b/irc/client_lookup_set.go index 2256c4f9..c97c89ff 100644 --- a/irc/client_lookup_set.go +++ b/irc/client_lookup_set.go @@ -117,7 +117,7 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick } if useAccountName { - if registered && newNick != accountName && newNick != "" { + if registered && newNick != accountName { return "", errNickAccountMismatch, false } newNick = accountName From 61fd7a25344dcd6d4a7195224ff2e990725afeea Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 24 Apr 2022 01:39:45 -0400 Subject: [PATCH 2/2] fix the rest of #1933 `NICK :` pre-registration needs to be special-cased to immediately send ERR_NONICKNAMEGIVEN (unlike erroneous nonempty nicknames, which are processed when registration is complete) --- irc/handlers.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/irc/handlers.go b/irc/handlers.go index 6374ad3c..0b95bbe1 100644 --- a/irc/handlers.go +++ b/irc/handlers.go @@ -2041,14 +2041,22 @@ func namesHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respon // NICK func nickHandler(server *Server, client *Client, msg ircmsg.Message, rb *ResponseBuffer) bool { + newNick := msg.Params[0] if client.registered { if client.account == "" && server.Config().Accounts.NickReservation.ForbidAnonNickChanges { rb.Add(nil, server.name, ERR_UNKNOWNERROR, client.Nick(), client.t("You may not change your nickname")) return false } - performNickChange(server, client, client, nil, msg.Params[0], rb) + performNickChange(server, client, client, nil, newNick, rb) } else { - client.preregNick = msg.Params[0] + if newNick == "" { + // #1933: this would leave (*Client).preregNick at its zero value of "", + // which is the same condition as NICK not having been sent yet --- + // so we need to send an error immediately + rb.Add(nil, server.name, ERR_NONICKNAMEGIVEN, "*", client.t("No nickname given")) + return false + } + client.preregNick = newNick } return false }