fix: Lock sessionListMutex in BroadcastLine()

This commit is contained in:
ChaoticByte 2024-06-29 09:57:51 +02:00
parent 2dd8f72714
commit 8538df7a14
No known key found for this signature in database

7
ssh.go
View file

@ -70,9 +70,10 @@ func RemoveFromSessionList(idx int) {
func BroadcastLine(line []byte) {
if logFlag { log.Printf("%s", line) } // output message
sessions := sessionList // create snapshot of client list
for i := range(len(sessions)) {
session := sessions[i]
sessionListMutex.Lock()
defer sessionListMutex.Unlock()
for i := range(len(sessionList)) {
session := sessionList[i]
if session != nil {
(*session).Write(line)
}