Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/agent/tokentracker/flock_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package tokentracker

import (
"fmt"
"math"
"os"
"syscall"
)
Expand All @@ -24,8 +25,13 @@ func acquireFileLock(path string) (release func(), err error) {
return nil, fmt.Errorf("open lock file: %w", err)
}

// Store fd as int to avoid unsafe uintptr -> int conversion (gosec G115)
fd := int(f.Fd())
// Safe conversion: validate uintptr fits in int (gosec G115)
uintptrVal := f.Fd()
if uintptrVal > uintptr(math.MaxInt) {
f.Close()
return nil, fmt.Errorf("file descriptor out of range: %v", uintptrVal)
}
Comment on lines +30 to +33
fd := int(uintptrVal)

if err := syscall.Flock(fd, syscall.LOCK_EX); err != nil {
f.Close()
Expand Down
Loading