Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ linters-settings:
includes:
- G101
- G102
- G103
- G303
- G601
revive:
Expand Down
3 changes: 3 additions & 0 deletions central/idmap/shared_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type sharedIDMapStorage struct {
// newSharedIDMapStorage creates a new shared storage for an ID map.
func newSharedIDMapStorage() *sharedIDMapStorage {
return &sharedIDMapStorage{
//#nosec G103
shared: unsafe.Pointer(NewIDMap()),
}
}
Expand All @@ -31,6 +32,7 @@ func (s *sharedIDMapStorage) Update(updater func(m *IDMap) bool) {
if sharedInstance == nil {
// If we have no shared instance, clone the current read-only instance.
sharedInstance = (*IDMap)(atomic.LoadPointer(&s.readOnly)).Clone()
//#nosec G103
atomic.StorePointer(&s.shared, unsafe.Pointer(sharedInstance))
}

Expand Down Expand Up @@ -58,6 +60,7 @@ func (s *sharedIDMapStorage) Get() *IDMap {

// Claim the current shared instance as the read-only instance.
m = (*IDMap)(atomic.LoadPointer(&s.shared))
//#nosec G103
atomic.StorePointer(&s.readOnly, unsafe.Pointer(m))
atomic.StorePointer(&s.shared, nil)

Expand Down
4 changes: 4 additions & 0 deletions pkg/concurrency/error_signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (s *errorSignalState) getErrPtr() *error {
}

func (s *errorSignalState) trigger(err error) bool {
//#nosec G103
if !atomic.CompareAndSwapPointer(&s.errPtr, nil, unsafe.Pointer(&err)) {
return false
}
Expand All @@ -129,6 +130,7 @@ func newErrorSignalState() *errorSignalState {

var (
defaultErrorSignalState = &errorSignalState{
//#nosec G103
errPtr: unsafe.Pointer(&[]error{nil}[0]),
signalC: closedCh,
}
Expand All @@ -144,6 +146,7 @@ type ErrorSignal struct {
// NewErrorSignal creates and returns a new error signal.
func NewErrorSignal() ErrorSignal {
return ErrorSignal{
//#nosec G103
statePtr: unsafe.Pointer(newErrorSignalState()),
}
}
Expand Down Expand Up @@ -187,6 +190,7 @@ func (s *ErrorSignal) ErrorAndReset() (Error, bool) {
// concurrent reset happened and succeeded, this Reset invocation will not. If the signal has been reset and
// triggered in the meantime, we fail, too, pretending this Reset invocation happened as the first action in a
// Reset - Trigger - Reset sequence.
//#nosec G103
if !atomic.CompareAndSwapPointer(&s.statePtr, unsafe.Pointer(rawState), unsafe.Pointer(newErrorSignalState())) {
return nil, false
}
Expand Down
1 change: 1 addition & 0 deletions pkg/concurrency/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (s *Signal) Wait() {
// actually performed (i.e., the signal was triggered). It returns false if the signal was not in the triggered state.
func (s *Signal) Reset() bool {
ch := make(chan struct{})
//#nosec G103
return atomic.CompareAndSwapPointer(&s.ch, nil, unsafe.Pointer(&ch))
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/concurrency/value_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type ValueStream[T any] struct {
// NewValueStream initializes a value stream with an initial value.
func NewValueStream[T any](initVal T) *ValueStream[T] {
return &ValueStream[T]{
//#nosec G103
curr: unsafe.Pointer(&valueStreamStrictIter[T]{
valueStreamIterBase: valueStreamIterBase[T]{
currVal: initVal,
Expand Down Expand Up @@ -172,6 +173,7 @@ func (s *ValueStream[T]) Push(val T) (T, ValueStreamIter[T]) {
},
}

//#nosec G103
oldIter := (*valueStreamStrictIter[T])(atomic.SwapPointer(&s.curr, unsafe.Pointer(newIter)))
oldIter.next = newIter
close(oldIter.nextC)
Expand Down
2 changes: 2 additions & 0 deletions pkg/grpc/authn/basic/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (m *Manager) hashFile() *htpasswd.HashFile {

// SetHashFile sets the hash file to be used for basic auth.
func (m *Manager) SetHashFile(hashFile *htpasswd.HashFile) {
//#nosec G103
atomic.StorePointer(&m.hashFilePtr, unsafe.Pointer(hashFile))
}

Expand All @@ -50,6 +51,7 @@ func (m *Manager) IdentityForCreds(ctx context.Context, username, password strin
// NewManager creates a new manager for basic authentication.
func NewManager(hashFile *htpasswd.HashFile, roleMapper permissions.RoleMapper) *Manager {
return &Manager{
//#nosec G103
hashFilePtr: unsafe.Pointer(hashFile),
mapper: roleMapper,
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/grpc/util/lazy_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type LazyClientConn struct {
// client conn type that returns an error right away.
func NewLazyClientConn() *LazyClientConn {
return &LazyClientConn{
//#nosec G103
state: unsafe.Pointer(makeState(nil)),
}
}
Expand All @@ -42,6 +43,7 @@ func NewLazyClientConn() *LazyClientConn {
// become available will be woken up, although they might block again soon afterwards if nil was specified.
func (c *LazyClientConn) Set(cc grpc.ClientConnInterface) {
newState := makeState(cc)
//#nosec G103
oldState := (*lazyConnState)(atomic.SwapPointer(&c.state, unsafe.Pointer(newState)))
if oldState.waitC != nil {
oldState.cc = cc
Expand Down
1 change: 1 addition & 0 deletions pkg/protoreflect/slice_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func identityOfSlice(slice []byte) sliceIdentity {
return sliceIdentity{}
}
return sliceIdentity{
//#nosec G103
base: uintptr(unsafe.Pointer(&slice[0])),
length: len(slice),
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sac/effectiveaccessscope/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func newUnvalidatedRequirement(key string, op selection.Operator, values []strin

setValue := func(fieldName string, value interface{}) {
field := reqUnleashed.FieldByName(fieldName)
//#nosec G103
field = reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem()
field.Set(reflect.ValueOf(value).Elem())
}
Expand Down
1 change: 1 addition & 0 deletions pkg/testutils/full_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func fullInitStruct(structVal reflect.Value, init BasicTypeInitializer, fieldFil
fieldVal := structVal.FieldByIndex(field.Index)
if field.Name != "" && unicode.IsLower([]rune(field.Name)[0]) {
// If a field is not exported, we need to make it writable with the following hack.
//#nosec G103
fieldVal = reflect.NewAt(fieldVal.Type(), unsafe.Pointer(fieldVal.UnsafeAddr())).Elem()
}
fullInitRecursive(fieldVal, init, fieldFilter, append(fieldPath, field), seenTypes)
Expand Down
1 change: 1 addition & 0 deletions sensor/admission-control/manager/manager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func (m *manager) ProcessNewSettings(newSettings *sensor.AdmissionControlSetting
m.cacheVersion = newSettings.GetCacheVersion()
}

//#nosec G103
atomic.StorePointer(&m.statePtr, unsafe.Pointer(newState))
if m.lastSettingsUpdate == nil {
log.Info("RE-ENABLING admission control service")
Expand Down