Skip to content

Commit c34c667

Browse files
committed
Java: Adjust to use the qlpack data-flow api.
1 parent 50e7892 commit c34c667

File tree

6 files changed

+27
-32
lines changed

6 files changed

+27
-32
lines changed

java/ql/lib/semmle/code/java/Type.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,7 @@ predicate notHaveIntersection(RefType t1, RefType t2) {
12611261
* Holds if there is a common (reflexive, transitive) subtype of the erased
12621262
* types `t1` and `t2`.
12631263
*/
1264+
pragma[nomagic]
12641265
predicate erasedHaveIntersection(RefType t1, RefType t2) {
12651266
exists(SrcRefType commonSub |
12661267
commonSub.getASourceSupertype*() = t1 and commonSub.getASourceSupertype*() = t2

java/ql/lib/semmle/code/java/dataflow/DataFlow.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java
77

88
module DataFlow {
9-
import semmle.code.java.dataflow.internal.DataFlow
9+
private import semmle.code.java.dataflow.internal.DataFlowImplSpecific
10+
private import codeql.dataflow.DataFlow
11+
import DataFlowMake<JavaDataFlow>
1012
import semmle.code.java.dataflow.internal.DataFlowImpl1
1113
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
private import DataFlowImplSpecific
2+
private import codeql.dataflow.DataFlowImpl
3+
import MakeImpl<JavaDataFlow>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
private import DataFlowImplSpecific
2+
private import codeql.dataflow.DataFlowImplCommon
3+
import MakeImplCommon<JavaDataFlow>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* Provides Java-specific definitions for use in the data flow library.
33
*/
4+
5+
private import codeql.dataflow.DataFlowParameter
6+
47
module Private {
58
import DataFlowPrivate
69
import DataFlowDispatch
@@ -9,3 +12,10 @@ module Private {
912
module Public {
1013
import DataFlowUtil
1114
}
15+
16+
module JavaDataFlow implements DataFlowParameter {
17+
import Private
18+
import Public
19+
20+
Node exprNode(DataFlowExpr e) { result = Public::exprNode(e) }
21+
}

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private predicate instanceFieldAssign(Expr src, FieldAccess fa) {
106106
* Thus, `node2` references an object with a field `f` that contains the
107107
* value of `node1`.
108108
*/
109-
predicate storeStep(Node node1, Content f, Node node2) {
109+
predicate storeStep(Node node1, ContentSet f, Node node2) {
110110
exists(FieldAccess fa |
111111
instanceFieldAssign(node1.asExpr(), fa) and
112112
node2.(PostUpdateNode).getPreUpdateNode() = getFieldQualifier(fa) and
@@ -124,7 +124,7 @@ predicate storeStep(Node node1, Content f, Node node2) {
124124
* Thus, `node1` references an object with a field `f` whose value ends up in
125125
* `node2`.
126126
*/
127-
predicate readStep(Node node1, Content f, Node node2) {
127+
predicate readStep(Node node1, ContentSet f, Node node2) {
128128
exists(FieldRead fr |
129129
node1 = getFieldQualifier(fr) and
130130
fr.getField() = f.(FieldContent).getField() and
@@ -156,7 +156,7 @@ predicate readStep(Node node1, Content f, Node node2) {
156156
* any value stored inside `f` is cleared at the pre-update node associated with `x`
157157
* in `x.f = newValue`.
158158
*/
159-
predicate clearsContent(Node n, Content c) {
159+
predicate clearsContent(Node n, ContentSet c) {
160160
exists(FieldAccess fa |
161161
instanceFieldAssign(_, fa) and
162162
n = getFieldQualifier(fa) and
@@ -207,47 +207,25 @@ DataFlowType getNodeType(Node n) {
207207
}
208208

209209
/** Gets a string representation of a type returned by `getErasedRepr`. */
210-
string ppReprType(Type t) {
210+
string ppReprType(DataFlowType t) {
211211
if t.(BoxedType).getPrimitiveType().getName() = "double"
212212
then result = "Number"
213213
else result = t.toString()
214214
}
215215

216-
private predicate canContainBool(Type t) {
217-
t instanceof BooleanType or
218-
any(BooleanType b).(RefType).getASourceSupertype+() = t
219-
}
220-
221216
/**
222217
* Holds if `t1` and `t2` are compatible, that is, whether data can flow from
223218
* a node of type `t1` to a node of type `t2`.
224219
*/
225-
pragma[inline]
226-
predicate compatibleTypes(Type t1, Type t2) {
227-
exists(Type e1, Type e2 |
228-
e1 = getErasedRepr(t1) and
229-
e2 = getErasedRepr(t2)
230-
|
231-
// Because of `getErasedRepr`, `erasedHaveIntersection` is a sufficient
232-
// compatibility check, but `conContainBool` is kept as a dummy disjunct
233-
// to get the proper join-order.
234-
erasedHaveIntersection(e1, e2)
235-
or
236-
canContainBool(e1) and canContainBool(e2)
237-
)
238-
}
220+
bindingset[t1, t2]
221+
pragma[inline_late]
222+
predicate compatibleTypes(DataFlowType t1, DataFlowType t2) { erasedHaveIntersection(t1, t2) }
239223

240224
/** A node that performs a type cast. */
241225
class CastNode extends ExprNode {
242226
CastNode() { this.getExpr() instanceof CastingExpr }
243227
}
244228

245-
/**
246-
* Holds if `n` should never be skipped over in the `PathGraph` and in path
247-
* explanations.
248-
*/
249-
predicate neverSkipInPathGraph(Node n) { none() }
250-
251229
private newtype TDataFlowCallable =
252230
TSrcCallable(Callable c) or
253231
TSummarizedCallable(SummarizedCallable c) or
@@ -381,8 +359,6 @@ predicate isUnreachableInCall(Node n, DataFlowCall call) {
381359
)
382360
}
383361

384-
int accessPathLimit() { result = 5 }
385-
386362
/**
387363
* Holds if access paths with `c` at their head always should be tracked at high
388364
* precision. This disables adaptive access path precision for such access paths.

0 commit comments

Comments
 (0)