Skip to content

Commit a7252e6

Browse files
committed
C++: Fix result duplication on 'cpp/unbounded-write' on 'kirxkirx/vast'.
1 parent 5de8934 commit a7252e6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,11 @@ predicate localInstructionFlow(Instruction e1, Instruction e2) {
16401640
localFlow(instructionNode(e1), instructionNode(e2))
16411641
}
16421642

1643+
/**
1644+
* INTERNAL: Do not use.
1645+
*/
16431646
cached
1644-
private module ExprFlowCached {
1647+
module ExprFlowCached {
16451648
/**
16461649
* Holds if `n` is an indirect operand of a `PointerArithmeticInstruction`, and
16471650
* `e` is the result of loading from the `PointerArithmeticInstruction`.
@@ -1692,7 +1695,8 @@ private module ExprFlowCached {
16921695
* `x[i]` steps to the expression `x[i - 1]` without traversing the
16931696
* entire chain.
16941697
*/
1695-
private Expr asExpr(Node n) {
1698+
cached
1699+
Expr asExprInternal(Node n) {
16961700
isIndirectBaseOfArrayAccess(n, result)
16971701
or
16981702
not isIndirectBaseOfArrayAccess(n, _) and
@@ -1704,7 +1708,7 @@ private module ExprFlowCached {
17041708
* dataflow step.
17051709
*/
17061710
private predicate localStepFromNonExpr(Node n1, Node n2) {
1707-
not exists(asExpr(n1)) and
1711+
not exists(asExprInternal(n1)) and
17081712
localFlowStep(n1, n2)
17091713
}
17101714

@@ -1715,7 +1719,7 @@ private module ExprFlowCached {
17151719
pragma[nomagic]
17161720
private predicate localStepsToExpr(Node n1, Node n2, Expr e2) {
17171721
localStepFromNonExpr*(n1, n2) and
1718-
e2 = asExpr(n2)
1722+
e2 = asExprInternal(n2)
17191723
}
17201724

17211725
/**
@@ -1726,7 +1730,7 @@ private module ExprFlowCached {
17261730
exists(Node mid |
17271731
localFlowStep(n1, mid) and
17281732
localStepsToExpr(mid, n2, e2) and
1729-
e1 = asExpr(n1)
1733+
e1 = asExprInternal(n1)
17301734
)
17311735
}
17321736

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private DataFlow::Node getNodeForSource(Expr source) {
6060
}
6161

6262
private DataFlow::Node getNodeForExpr(Expr node) {
63-
result = DataFlow::exprNode(node)
63+
node = DataFlow::ExprFlowCached::asExprInternal(result)
6464
or
6565
// Some of the sources in `isUserInput` are intended to match the value of
6666
// an expression, while others (those modeled below) are intended to match
@@ -221,7 +221,7 @@ private module Cached {
221221
predicate nodeIsBarrierIn(DataFlow::Node node) {
222222
// don't use dataflow into taint sources, as this leads to duplicate results.
223223
exists(Expr source | isUserInput(source, _) |
224-
node = DataFlow::exprNode(source)
224+
source = DataFlow::ExprFlowCached::asExprInternal(node)
225225
or
226226
// This case goes together with the similar (but not identical) rule in
227227
// `getNodeForSource`.

0 commit comments

Comments
 (0)