Skip to content

Commit 5dbaea8

Browse files
committed
C++: Add a special dataflow step from InitializeIndirection instructions.
1 parent b1ea00f commit 5dbaea8

File tree

1 file changed

+18
-0
lines changed
  • cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal

1 file changed

+18
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/Ssa.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,24 @@ private module Cached {
382382
fromPhiNode(nodeFrom, nodeTo)
383383
or
384384
toPhiNode(nodeFrom, nodeTo)
385+
or
386+
// When we want to transfer flow out of a `StoreNode` we perform two steps:
387+
// 1. Find the next use of the address being stored to
388+
// 2. Find the `LoadInstruction` that loads the address
389+
// When the address being stored into doesn't have a `LoadInstruction` associated with it because it's
390+
// passed into a `CallInstruction` we transfer flow to the `ReadSideEffect`, which will then flow into
391+
// the callee. We then pickup the flow from the `InitializeIndirectionInstruction` and use the shared
392+
// SSA library to determine where the next use of the address that received the flow is.
393+
exists(Node init, Node mid |
394+
nodeFrom.asInstruction().(InitializeIndirectionInstruction).getIRVariable() =
395+
init.asInstruction().(InitializeParameterInstruction).getIRVariable() and
396+
// No need for the flow if the next use is the instruction that returns the flow out of the callee.
397+
not mid.asInstruction() instanceof ReturnIndirectionInstruction and
398+
// Find the next use of the address
399+
ssaFlow(init, mid) and
400+
// And flow to the next load of that address
401+
flowOutOfAddressStep([mid.asInstruction().getAUse(), mid.asOperand()], nodeTo)
402+
)
385403
}
386404

387405
private predicate flowOutOfAddressStep(Operand operand, Node nTo) {

0 commit comments

Comments
 (0)