From 8f1bc93cca17fdef4eff574e0cbcd053f11c03d7 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 28 Apr 2023 16:51:17 +0200 Subject: [PATCH] Protect against clients with an empty id. --- group/group.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/group/group.go b/group/group.go index 42c5763..3fa0f36 100644 --- a/group/group.go +++ b/group/group.go @@ -609,17 +609,18 @@ func AddClient(group string, c Client, creds ClientCredentials) (*Group, error) } } } - - if g.clients[c.Id()] != nil { + id := c.Id() + if id == "" { + return nil, errors.New("client has empty id") + } + if g.clients[id] != nil { return nil, ProtocolError("duplicate client id") } - - g.clients[c.Id()] = c + g.clients[id] = c g.timestamp = time.Now() c.Joined(g.Name(), "join") - id := c.Id() u := c.Username() p := c.Permissions() s := c.Data()