Skip to content

Commit 51f5740

Browse files
committed
C++: Exclude functions that aren't declared inside the source root. This fixes performance on ImageMagick.
1 parent 6a563c1 commit 51f5740

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cpp/ql/src/Likely Bugs/Format/NonConstantFormat.ql

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ predicate dataFlowOrTaintFlowFunction(Function func, FunctionOutput output) {
6363
func.(TaintFunction).hasTaintFlow(_, output)
6464
}
6565

66+
/** Holds if `func` is declared inside the source root. */
67+
predicate isInsideSourceRoot(Function func) {
68+
exists(File f |
69+
f = func.getFile() and
70+
exists(f.getRelativePath())
71+
)
72+
}
73+
6674
/**
6775
* Holds if `node` is a non-constant source of data flow for non-const format string detection.
6876
* This is defined as either:
@@ -111,7 +119,8 @@ predicate isNonConst(DataFlow::Node node) {
111119
// The function's output must also not be const to be considered a non-const source
112120
exists(Function func, CallInstruction call |
113121
not func.hasDefinition() and
114-
func = call.getStaticCallTarget()
122+
func = call.getStaticCallTarget() and
123+
isInsideSourceRoot(func)
115124
|
116125
// Case 1: It's a known dataflow or taintflow function with flow to the return value
117126
call.getUnconvertedResultExpression() = node.asIndirectExpr() and

0 commit comments

Comments
 (0)