Skip to content

Commit

Permalink
protect tracked files with mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
capnspacehook authored and github-actions committed Oct 30, 2024
1 parent e9516e2 commit c83e2e4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tool/teleport/common/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"os/user"
"path"
"strings"
"sync"
"sync/atomic"
"time"

Expand Down Expand Up @@ -90,8 +91,12 @@ type allowedOps struct {
type sftpHandler struct {
logger *log.Entry
allowed *allowedOps
files []*trackedFile
events chan<- apievents.AuditEvent

// mtx protects files
mtx sync.Mutex
files []*trackedFile

events chan<- apievents.AuditEvent
}

type trackedFile struct {
Expand Down Expand Up @@ -245,7 +250,9 @@ func (s *sftpHandler) openFile(req *sftp.Request) (sftp.WriterAtReaderAt, error)
return nil, err
}
trackFile := &trackedFile{file: f}
s.mtx.Lock()
s.files = append(s.files, trackFile)
s.mtx.Unlock()

return trackFile, nil
}
Expand Down

0 comments on commit c83e2e4

Please sign in to comment.