Fix race condition in session maker

This commit is contained in:
Andy Wang 2020-12-18 23:05:54 +00:00
parent 22148852dc
commit 900387832d
No known key found for this signature in database
GPG Key ID: 181B49F9F38F3374
2 changed files with 2 additions and 3 deletions

View File

@ -169,6 +169,7 @@ func main() {
}
log.Infof("Listening on %v %v for %v client", network, localConfig.LocalAddr, authInfo.ProxyMethod)
seshMaker = func() *mux.Session {
authInfo := authInfo // copy the struct because we are overwriting SessionId
// sessionID is usergenerated. There shouldn't be a security concern because the scope of
// sessionID is limited to its UID.
quad := make([]byte, 4)

View File

@ -185,11 +185,9 @@ func establishSession(lcc client.LocalConnConfig, rcc client.RemoteConnConfig, a
// whatever connection initiator (including a proper ck-client)
netToCkServerD, ckServerListener := connutil.DialerListener(10 * 1024)
var sessionCreateMutex sync.Mutex
clientSeshMaker := func() *mux.Session {
sessionCreateMutex.Lock()
defer sessionCreateMutex.Unlock()
ai := ai
quad := make([]byte, 4)
common.RandRead(ai.WorldState.Rand, quad)
ai.SessionId = binary.BigEndian.Uint32(quad)