forked from trailofbits/semgrep-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
racy-append-to-slice.yaml
55 lines (54 loc) · 1.35 KB
/
racy-append-to-slice.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
43
44
45
46
47
48
49
50
51
52
53
54
55
rules:
- id: racy-append-to-slice
message: >-
Appending `$SLICE` 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 calls to `append` from multiple goroutines"
references:
- https://go.dev/blog/maps#concurrency
patterns:
- pattern: |
$SLICE = append($SLICE, $ITEM)
- pattern-either:
- pattern-inside: |
var $SLICE []$TYPE
...
for ... {
...
go func(...) {
...
$SLICE = append($SLICE, ...)
...
}(...)
...
}
- pattern-inside: |
$SLICE := make([]$TYPE, ...)
...
for ... {
...
go func(...) {
...
$SLICE = append($SLICE, ...)
...
}(...)
...
}
- pattern-not-inside: |
$MUTEX.Lock()
...
$MUTEX.Unlock()
- pattern-not-inside: |
$MUTEX.Lock()
...
defer $MUTEX.Unlock()
...