aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-11-08 09:03:49 -0800
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-11-08 09:03:49 -0800
commitf4cdaddcc62318dd1a10b4a287102762c41710e2 (patch)
tree87f0a818c1e7c0bb4866aef6d382471c910dc4cf /hotline
parent6c67b0a53e6b894342e91a8533f3bee3adf64346 (diff)
Fix overwrite of user info due to buffer re-use
Diffstat (limited to 'hotline')
-rw-r--r--hotline/server.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/hotline/server.go b/hotline/server.go
index 164b93e..bd15a2e 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -565,8 +565,13 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
scanner.Scan()
+ // Make a new []byte slice and copy the scanner bytes to it. This is critical to avoid a data race as the
+ // scanner re-uses the buffer for subsequent scans.
+ buf := make([]byte, len(scanner.Bytes()))
+ copy(buf, scanner.Bytes())
+
var clientLogin Transaction
- if _, err := clientLogin.Write(scanner.Bytes()); err != nil {
+ if _, err := clientLogin.Write(buf); err != nil {
return err
}