Skip to content

Commit 0783d46

Browse files
committed
C++: Fix a object->pointer conflation problem. This piece of code was
supposed to send flow from the `InitializeIndirection` instruction to the next use of the memory defined by that instruction, but it didn't actually call `flowOutOfAddressStep` on the result of the call to `ssaFlow` to ensure that we moved from the pointer to the object.
1 parent 8426857 commit 0783d46

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -734,21 +734,6 @@ predicate simpleLocalFlowStep(Node nodeFrom, Node nodeTo) {
734734
or
735735
// Adjacent-def-use and adjacent-use-use flow
736736
adjacentDefUseFlow(nodeFrom, nodeTo)
737-
or
738-
// When we want to transfer flow out of a `StoreNode` we perform two steps:
739-
// 1. Find the next use of the address being stored to
740-
// 2. Find the `LoadInstruction` that loads the address
741-
// When the address being stored into doesn't have a `LoadInstruction` associated with it because it's
742-
// passed into a `CallInstruction` we transfer flow to the `ReadSideEffect`, which will then flow into
743-
// the callee. We then pickup the flow from the `InitializeIndirectionInstruction` and use the shared
744-
// SSA library to determine where the next use of the address that received the flow is.
745-
exists(Node init |
746-
nodeFrom.asInstruction().(InitializeIndirectionInstruction).getIRVariable() =
747-
init.asInstruction().(InitializeParameterInstruction).getIRVariable() and
748-
// No need for the flow if the next use is the instruction that returns the flow out of the callee.
749-
not nodeTo.asInstruction() instanceof ReturnIndirectionInstruction and
750-
Ssa::ssaFlow(init, nodeTo)
751-
)
752737
}
753738

754739
private predicate adjacentDefUseFlow(Node nodeFrom, Node nodeTo) {

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
@@ -403,6 +403,24 @@ private module Cached {
403403
fromPhiNode(nodeFrom, nodeTo)
404404
or
405405
toPhiNode(nodeFrom, nodeTo)
406+
or
407+
// When we want to transfer flow out of a `StoreNode` we perform two steps:
408+
// 1. Find the next use of the address being stored to
409+
// 2. Find the `LoadInstruction` that loads the address
410+
// When the address being stored into doesn't have a `LoadInstruction` associated with it because it's
411+
// passed into a `CallInstruction` we transfer flow to the `ReadSideEffect`, which will then flow into
412+
// the callee. We then pickup the flow from the `InitializeIndirectionInstruction` and use the shared
413+
// SSA library to determine where the next use of the address that received the flow is.
414+
exists(Node init, Node mid |
415+
nodeFrom.asInstruction().(InitializeIndirectionInstruction).getIRVariable() =
416+
init.asInstruction().(InitializeParameterInstruction).getIRVariable() and
417+
// No need for the flow if the next use is the instruction that returns the flow out of the callee.
418+
not mid.asInstruction() instanceof ReturnIndirectionInstruction and
419+
// Find the next use of the address
420+
ssaFlow(init, mid) and
421+
// And flow to the next load of that address
422+
flowOutOfAddressStep([mid.asInstruction().getAUse(), mid.asOperand()], nodeTo)
423+
)
406424
}
407425

408426
private predicate valueFlow(Instruction iFrom, Instruction iTo) {

0 commit comments

Comments
 (0)