Skip to content

Commit 3832100

Browse files
author
Dave Bartolomeo
committed
C++: Isolate models from AST dataflow's reference/object conflation
`DataFlowFunction` models treat references a pointers - an explicit level of indirection. The AST dataflow library generally treats references as if they were the referred-to object. This commit removes a workaround in the dataflow model for unary `operator*` on smart pointers, and makes the AST dataflow library adjust the results of querying the model so that a returned reference only gets flow that was modeled as going to the dereference of the return value. This fixes some missing flow in IR dataflow, and recovers some (presumably) missing reverse taint flow in AST taint tracking as well.
1 parent 0bc4b04 commit 3832100

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowUtil.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,12 @@ private predicate exprToExprStep_nocfg(Expr fromExpr, Expr toExpr) {
694694
fromExpr = call.getQualifier()
695695
) and
696696
call.getTarget() = f and
697-
outModel.isReturnValue()
697+
// AST dataflow treats a reference as if it were the referred-to object, while the dataflow
698+
// models treat references as pointers. If the return type of the call is a reference, then
699+
// look for data flow the the referred-to object, rather than the reference itself.
700+
if call.getType().getUnspecifiedType() instanceof ReferenceType
701+
then outModel.isReturnValueDeref()
702+
else outModel.isReturnValue()
698703
)
699704
)
700705
}

0 commit comments

Comments
 (0)