mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
whitelist calls to functions that always throw an exception
This commit is contained in:
@@ -21,8 +21,6 @@ predicate returnsVoid(Function f) {
|
||||
}
|
||||
|
||||
predicate isStub(Function f) {
|
||||
f.getBodyStmt(0) instanceof ThrowStmt
|
||||
or
|
||||
f.getBody().(BlockStmt).getNumChild() = 0
|
||||
or
|
||||
f instanceof ExternalDecl
|
||||
@@ -76,10 +74,20 @@ predicate oneshotClosure(InvokeExpr call) {
|
||||
call.getCallee().getUnderlyingValue() instanceof ImmediatelyInvokedFunctionExpr
|
||||
}
|
||||
|
||||
predicate alwaysThrows(Function f) {
|
||||
exists(ReachableBasicBlock entry, DataFlow::Node throwNode |
|
||||
entry = f.getEntryBB() and
|
||||
throwNode.asExpr() = any(ThrowStmt t).getExpr() and
|
||||
entry.dominates(throwNode.getBasicBlock())
|
||||
)
|
||||
}
|
||||
|
||||
from DataFlow::CallNode call
|
||||
where
|
||||
not call.isIndefinite(_) and
|
||||
forex(Function f | f = call.getACallee() | returnsVoid(f) and not isStub(f)) and
|
||||
forex(Function f | f = call.getACallee() |
|
||||
returnsVoid(f) and not isStub(f) and not alwaysThrows(f)
|
||||
) and
|
||||
|
||||
not benignContext(call.asExpr()) and
|
||||
|
||||
|
||||
Reference in New Issue
Block a user