Skip to content

Commit 150d4f3

Browse files
committed
C++: Fix looping flow that goes from the output argument node and back into the function argument.
1 parent 35e91ba commit 150d4f3

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -657,24 +657,16 @@ private predicate indirectConversionFlowStep(Node nFrom, Node nTo) {
657657
* So this predicate recurses back along conversions and `PointerArithmeticInstruction`s to find the
658658
* first use that has provides use-use flow, and uses that target as the target of the `nodeFrom`.
659659
*/
660-
private predicate adjustForPointerArith(
661-
DefOrUse defOrUse, Node nodeFrom, UseOrPhi use, boolean uncertain
662-
) {
663-
nodeFrom = any(PostUpdateNode pun).getPreUpdateNode() and
664-
exists(Node adjusted |
665-
indirectConversionFlowStep*(adjusted, nodeFrom) and
666-
nodeToDefOrUse(adjusted, defOrUse, uncertain) and
660+
private predicate adjustForPointerArith(PostUpdateNode pun, UseOrPhi use) {
661+
exists(DefOrUse defOrUse, Node adjusted |
662+
indirectConversionFlowStep*(adjusted, pun.getPreUpdateNode()) and
663+
nodeToDefOrUse(adjusted, defOrUse, _) and
667664
adjacentDefRead(defOrUse, use)
668665
)
669666
}
670667

671668
private predicate ssaFlowImpl(SsaDefOrUse defOrUse, Node nodeFrom, Node nodeTo, boolean uncertain) {
672-
// `nodeFrom = any(PostUpdateNode pun).getPreUpdateNode()` is implied by adjustedForPointerArith.
673669
exists(UseOrPhi use |
674-
adjustForPointerArith(defOrUse, nodeFrom, use, uncertain) and
675-
useToNode(use, nodeTo)
676-
or
677-
not nodeFrom = any(PostUpdateNode pun).getPreUpdateNode() and
678670
nodeToDefOrUse(nodeFrom, defOrUse, uncertain) and
679671
adjacentDefRead(defOrUse, use) and
680672
useToNode(use, nodeTo) and
@@ -719,14 +711,19 @@ predicate ssaFlow(Node nodeFrom, Node nodeTo) {
719711
)
720712
}
721713

714+
private predicate isArgumentOfCallable(DataFlowCall call, ArgumentNode arg) {
715+
arg.argumentOf(call, _)
716+
}
717+
718+
/** Holds if there is def-use or use-use flow from `pun` to `nodeTo`. */
722719
predicate postUpdateFlow(PostUpdateNode pun, Node nodeTo) {
723-
exists(Node preUpdate, Node nFrom, boolean uncertain, SsaDefOrUse defOrUse |
720+
exists(UseOrPhi use, Node preUpdate |
721+
adjustForPointerArith(pun, use) and
722+
useToNode(use, nodeTo) and
724723
preUpdate = pun.getPreUpdateNode() and
725-
ssaFlowImpl(defOrUse, nFrom, nodeTo, uncertain)
726-
|
727-
if uncertain = true
728-
then preUpdate = [nFrom, getAPriorDefinition(defOrUse)]
729-
else preUpdate = nFrom
724+
not exists(DataFlowCall call |
725+
isArgumentOfCallable(call, preUpdate) and isArgumentOfCallable(call, nodeTo)
726+
)
730727
)
731728
}
732729

0 commit comments

Comments
 (0)