-
Notifications
You must be signed in to change notification settings - Fork 38
/
missing-unlock-before-return.yaml
55 lines (54 loc) · 1.47 KB
/
missing-unlock-before-return.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: missing-unlock-before-return
message: >-
Missing mutex unlock (`$T` variable) before returning from a function.
This could result in panics resulting from double lock operations
languages: [go]
severity: ERROR
metadata:
category: security
cwe: "CWE-667: Improper Locking"
subcategory: [vuln]
confidence: MEDIUM
likelihood: HIGH
impact: MEDIUM
technology: [--no-technology--]
description: "Missing `mutex` unlock before returning from a function"
references:
- https://pkg.go.dev/sync#Mutex
- https://blog.trailofbits.com/2020/06/09/how-to-check-if-a-mutex-is-locked-in-go/
patterns:
- pattern-either:
- pattern: panic(...)
- pattern: return ...
- metavariable-pattern:
metavariable: $T
patterns:
- pattern: |
($T : sync.Mutex)
- pattern-inside: |
$T.Lock()
...
- pattern-not-inside: |
$T.Unlock()
...
- pattern-not-inside: |
defer $T.Unlock()
...
- pattern-not-inside: |
defer func(...) {
...
$T.Unlock()
...
}(...)
...
- pattern-not-inside: |
$FOO(..., ..., func(...) {
...
})
- pattern-not-inside: |
return func(...) {
...
$T.Unlock()
...
}