Skip to content

Commit 95ebbb1

Browse files
committed
Ql alterations for cleanup as part of merge suggestions.
1 parent 1fb7f08 commit 95ebbb1

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,25 @@ predicate isNonConst(DataFlow::Node node) {
7777
// i.e., functions that with unknown bodies and are not known to define the output through its input
7878
// are considered as possible non-const sources
7979
// The function's output must also not be const to be considered a non-const source
80-
exists(Call c |
81-
exists(Expr arg | c.getAnArgument() = arg | arg = node.asDefiningArgument())
80+
exists(Function func, CallInstruction call |
81+
// NOTE: could use `Call` getAnArgument() instead of `CallInstruction` but requires two
82+
// variables representing the same call.
83+
exists(Expr arg | call.getPositionalArgumentOperand(_).getDef().getUnconvertedResultExpression() = arg and
84+
arg = node.asDefiningArgument()
85+
)
8286
or
83-
c = node.asIndirectExpr()
84-
) and
85-
not exists(FunctionInput input, FunctionOutput output, CallInstruction call |
86-
// NOTE: we must include dataflow and taintflow. e.g., including only dataflow we will find sprintf
87-
// variant function's output are now possible non-const sources
88-
(
89-
pragma[only_bind_out](call.getStaticCallTarget())
90-
.(DataFlowFunction)
91-
.hasDataFlow(input, output) or
92-
pragma[only_bind_out](call.getStaticCallTarget()).(TaintFunction).hasTaintFlow(input, output)
93-
) and
94-
node = callOutput(call, output)
95-
) and
96-
not exists(Call c |
87+
call.getUnconvertedResultExpression() = node.asIndirectExpr()
88+
|
89+
func = call.getStaticCallTarget() and
90+
not exists(FunctionOutput output |
91+
// NOTE: we must include dataflow and taintflow. e.g., including only dataflow we will find sprintf
92+
// variant function's output are now possible non-const sources
93+
pragma[only_bind_out](func).(DataFlowFunction).hasDataFlow(_, output) or
94+
pragma[only_bind_out](func).(TaintFunction).hasTaintFlow(_, output)
95+
|
96+
node = callOutput(call, output)
97+
)
98+
) not exists(Call c |
9799
c.getTarget().hasDefinition() and
98100
if node instanceof DataFlow::DefinitionByReferenceNode
99101
then c.getAnArgument() = node.asDefiningArgument()

0 commit comments

Comments
 (0)