Skip to content

Mutex Copied via Value Receiver

Description

A `sync.Mutex` is copied in a function given that the receiver is a value. As a result, the struct may not be locked as intended, potentially leading to concurrency issues.

Examples

Insecure Code

go
func (m myStruct) myFunction() { m.Lock(); }

Secure Code

go
func (m *myStruct) myFunction() { m.Lock(); }

Remediation

Change the receiver to a pointer to ensure the mutex is not copied.

Rule Details

FieldValue
IDCODE-0257
CategoryConcurrency
SeverityMEDIUM
CWECWE-688
ConfidenceHIGH
ImpactLOW
LikelihoodHIGH
ExploitabilityMODERATE
Tagsconcurrency, mutex
OWASPN/A

References