-
Notifications
You must be signed in to change notification settings - Fork 38
/
racy-write-to-map.yaml
42 lines (41 loc) · 1.09 KB
/
racy-write-to-map.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
rules:
- id: racy-write-to-map
message: >-
Writing `$MAP` from multiple goroutines is not concurrency safe
languages: [go]
severity: ERROR
metadata:
category: security
cwe: "CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')"
subcategory: [vuln]
confidence: MEDIUM
likelihood: HIGH
impact: MEDIUM
technology: [--no-technology--]
description: "Concurrent writes to the same map in multiple goroutines"
references:
- https://go.dev/blog/maps#concurrency
patterns:
- pattern: |
$MAP[$KEY] = $VALUE
- pattern-inside: |
$MAP = make(map[$KTYPE]$VTYPE)
...
for ... {
...
go func(...) {
...
$MAP[$KEY] = $VALUE
...
}(...)
...
}
- pattern-not-inside: |
$MUTEX.Lock()
...
$MUTEX.Unlock()
- pattern-not-inside: |
$MUTEX.Lock()
...
defer $MUTEX.Unlock()
...