C++: Exclude functions that aren't declared inside the source root. This fixes performance on ImageMagick.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-03-12 14:16:46 +00:00
parent 6a563c161e
commit 51f5740707

View File

@@ -63,6 +63,14 @@ predicate dataFlowOrTaintFlowFunction(Function func, FunctionOutput output) {
func.(TaintFunction).hasTaintFlow(_, output)
}
/** Holds if `func` is declared inside the source root. */
predicate isInsideSourceRoot(Function func) {
exists(File f |
f = func.getFile() and
exists(f.getRelativePath())
)
}
/**
* Holds if `node` is a non-constant source of data flow for non-const format string detection.
* This is defined as either:
@@ -111,7 +119,8 @@ predicate isNonConst(DataFlow::Node node) {
// The function's output must also not be const to be considered a non-const source
exists(Function func, CallInstruction call |
not func.hasDefinition() and
func = call.getStaticCallTarget()
func = call.getStaticCallTarget() and
isInsideSourceRoot(func)
|
// Case 1: It's a known dataflow or taintflow function with flow to the return value
call.getUnconvertedResultExpression() = node.asIndirectExpr() and