forked from trailofbits/semgrep-rules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaitgroup-add-called-inside-goroutine.yaml
48 lines (46 loc) · 1.12 KB
/
waitgroup-add-called-inside-goroutine.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
rules:
- id: waitgroup-add-called-inside-goroutine
message: |
Calling `$WG.Add` inside of an anonymous goroutine may result in `$WG.Wait`
waiting for more or less calls to `$WG.Done()` than expected
languages: [go]
severity: ERROR
metadata:
category: security
cwe: "CWE-667: Improper Locking"
subcategory: [vuln]
confidence: MEDIUM
likelihood: MEDIUM
impact: MEDIUM
technology: [--no-technology--]
description: "Calls to `sync.WaitGroup.Add` inside of anonymous goroutines"
references:
- https://go101.org/article/concurrent-common-mistakes.html
patterns:
- pattern-either:
- pattern: |
$WG := &sync.WaitGroup{}
...
go func(...) {
...
$WG.Add(...)
...
}(...)
...
$WG.Wait()
- pattern: |
var $WG sync.WaitGroup
...
go func(...) {
...
$WG.Add(...)
...
}(...)
...
$WG.Wait()
- pattern-not-inside: |
for ... {
...
$WG.Add(...)
...
}