]> git.r.bdr.sh - rbdr/mobius/commitdiff
Fix overwrite of user info due to buffer re-use
authorJeff Halter <redacted>
Tue, 8 Nov 2022 17:03:49 +0000 (09:03 -0800)
committerJeff Halter <redacted>
Tue, 8 Nov 2022 17:03:49 +0000 (09:03 -0800)
hotline/server.go

index 164b93ec1fa5045afae838fe939b80ffda35c331..bd15a2ecea697b8ed88a2e34c29e870b6866e034 100644 (file)
@@ -565,8 +565,13 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
 
        scanner.Scan()
 
 
        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
        var clientLogin Transaction
-       if _, err := clientLogin.Write(scanner.Bytes()); err != nil {
+       if _, err := clientLogin.Write(buf); err != nil {
                return err
        }
 
                return err
        }