-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathRedundantRecover.ql
More file actions
35 lines (32 loc) · 1.04 KB
/
RedundantRecover.ql
File metadata and controls
35 lines (32 loc) · 1.04 KB
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
/**
* @name Redundant call to recover
* @description Calling 'recover' in a function which isn't called using a defer
* statement has no effect. Also, putting 'recover' directly in a
* defer statement has no effect.
* @kind problem
* @problem.severity warning
* @id go/redundant-recover
* @tags quality
* reliability
* correctness
* external/cwe/cwe-248
* @precision high
*/
import go
predicate isDeferred(DataFlow::CallNode call) {
exists(DeferStmt defer | defer.getCall() = call.asExpr())
}
from DataFlow::CallNode recoverCall, FuncDef f, string msg
where
recoverCall.getTarget() = Builtin::recover() and
f = recoverCall.getRoot() and
(
isDeferred(recoverCall) and
msg = "Deferred calls to 'recover' have no effect."
or
not isDeferred(recoverCall) and
exists(f.getACall()) and
not isDeferred(f.getACall()) and
msg = "This call to 'recover' has no effect because $@ is never called using a defer statement."
)
select recoverCall, msg, f, "the enclosing function"