Skip to content

Commit 6a563c1

Browse files
committed
C++: Simplify the definition of 'isNonConst'. On ImageMagick I get the same exact sources before and after.
1 parent 179a7d5 commit 6a563c1

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,28 @@ predicate isNonConst(DataFlow::Node node) {
109109
// i.e., functions that with unknown bodies and are not known to define the output through its input
110110
// are considered as possible non-const sources
111111
// The function's output must also not be const to be considered a non-const source
112-
(
112+
exists(Function func, CallInstruction call |
113+
not func.hasDefinition() and
114+
func = call.getStaticCallTarget()
115+
|
113116
// Case 1: It's a known dataflow or taintflow function with flow to the return value
114-
exists(Function func, CallInstruction call |
115-
call.getUnconvertedResultExpression() = node.asIndirectExpr() and
116-
func = call.getStaticCallTarget() and
117-
not exists(FunctionOutput output |
118-
dataFlowOrTaintFlowFunction(func, output) and
119-
output.isReturnValueDeref() and
120-
node = callOutput(call, output)
121-
)
117+
call.getUnconvertedResultExpression() = node.asIndirectExpr() and
118+
not exists(FunctionOutput output |
119+
dataFlowOrTaintFlowFunction(func, output) and
120+
output.isReturnValueDeref(_) and
121+
node = callOutput(call, output)
122122
)
123123
or
124-
// Case 1: It's a known dataflow or taintflow function with flow to an output parameter
125-
exists(Function func, int i, CallInstruction call |
124+
// Case 2: It's a known dataflow or taintflow function with flow to an output parameter
125+
exists(int i |
126126
call.getPositionalArgumentOperand(i).getDef().getUnconvertedResultExpression() =
127127
node.asDefiningArgument() and
128-
func = call.getStaticCallTarget() and
129128
not exists(FunctionOutput output |
130129
dataFlowOrTaintFlowFunction(func, output) and
131-
output.isParameterDeref(i) and
130+
output.isParameterDeref(i, _) and
132131
node = callOutput(call, output)
133132
)
134133
)
135-
) and
136-
not exists(Call c |
137-
c.getTarget().hasDefinition() and
138-
if node instanceof DataFlow::DefinitionByReferenceNode
139-
then c.getAnArgument() = node.asDefiningArgument()
140-
else c = node.asIndirectExpr()
141134
)
142135
}
143136

0 commit comments

Comments
 (0)