Skip to content

Commit 651d9d0

Browse files
committed
Java: Ensure cached predicates are in the same stage.
1 parent 0e830f6 commit 651d9d0

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowUtil.qll

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,42 @@ predicate hasNonlocalValue(FieldRead fr) {
9999
)
100100
}
101101

102-
/**
103-
* Holds if data can flow from `node1` to `node2` in one local step.
104-
*/
105102
cached
106-
predicate localFlowStep(Node node1, Node node2) {
107-
simpleLocalFlowStep0(node1, node2)
108-
or
109-
adjacentUseUse(node1.asExpr(), node2.asExpr())
110-
or
111-
// Simple flow through library code is included in the exposed local
112-
// step relation, even though flow is technically inter-procedural
113-
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(node1, node2)
114-
}
103+
private module Cached {
104+
/**
105+
* Holds if data can flow from `node1` to `node2` in one local step.
106+
*/
107+
cached
108+
predicate localFlowStep(Node node1, Node node2) {
109+
simpleLocalFlowStep0(node1, node2)
110+
or
111+
adjacentUseUse(node1.asExpr(), node2.asExpr())
112+
or
113+
// Simple flow through library code is included in the exposed local
114+
// step relation, even though flow is technically inter-procedural
115+
FlowSummaryImpl::Private::Steps::summaryThroughStepValue(node1, node2)
116+
}
115117

116-
/**
117-
* INTERNAL: do not use.
118-
*
119-
* This is the local flow predicate that's used as a building block in global
120-
* data flow. It may have less flow than the `localFlowStep` predicate.
121-
*/
122-
cached
123-
predicate simpleLocalFlowStep(Node node1, Node node2) {
124-
simpleLocalFlowStep0(node1, node2)
125-
or
126-
any(AdditionalValueStep a).step(node1, node2) and
127-
pragma[only_bind_out](node1.getEnclosingCallable()) =
128-
pragma[only_bind_out](node2.getEnclosingCallable()) and
129-
// prevent recursive call
130-
(any(AdditionalValueStep a).step(_, _) implies any())
118+
/**
119+
* INTERNAL: do not use.
120+
*
121+
* This is the local flow predicate that's used as a building block in global
122+
* data flow. It may have less flow than the `localFlowStep` predicate.
123+
*/
124+
cached
125+
predicate simpleLocalFlowStep(Node node1, Node node2) {
126+
simpleLocalFlowStep0(node1, node2)
127+
or
128+
any(AdditionalValueStep a).step(node1, node2) and
129+
pragma[only_bind_out](node1.getEnclosingCallable()) =
130+
pragma[only_bind_out](node2.getEnclosingCallable()) and
131+
// prevent recursive call
132+
(any(AdditionalValueStep a).step(_, _) implies any())
133+
}
131134
}
132135

136+
import Cached
137+
133138
private predicate simpleLocalFlowStep0(Node node1, Node node2) {
134139
TaintTrackingUtil::forceCachingInSameStage() and
135140
// Variable flow steps through adjacent def-use and use-use pairs.

0 commit comments

Comments
 (0)