9
9
import java
10
10
private import VirtualDispatch
11
11
private import semmle.code.java.dataflow.internal.BaseSSA
12
- private import semmle.code.java.dataflow.internal.DataFlowUtil
13
- private import semmle.code.java.dataflow.internal.DataFlowPrivate
12
+ private import semmle.code.java.dataflow.internal.DataFlowUtil as DataFlow
13
+ private import semmle.code.java.dataflow.internal.DataFlowPrivate as DataFlowPrivate
14
14
private import semmle.code.java.dataflow.InstanceAccess
15
15
private import semmle.code.java.Collections
16
16
private import semmle.code.java.Maps
@@ -122,7 +122,7 @@ private predicate relevant(RefType t) {
122
122
}
123
123
124
124
/** A node with a type that is relevant for dispatch flow. */
125
- private class RelevantNode extends Node {
125
+ private class RelevantNode extends DataFlow :: Node {
126
126
RelevantNode ( ) { relevant ( this .getType ( ) ) }
127
127
}
128
128
@@ -131,8 +131,8 @@ private class RelevantNode extends Node {
131
131
* The instance parameter is considered to have index `-1`.
132
132
*/
133
133
pragma [ nomagic]
134
- private predicate viableParamCand ( Call call , int i , ParameterNode p ) {
135
- exists ( DataFlowCallable callable |
134
+ private predicate viableParamCand ( Call call , int i , DataFlow :: ParameterNode p ) {
135
+ exists ( DataFlowPrivate :: DataFlowCallable callable |
136
136
callable .asCallable ( ) = dispatchCand ( call ) and
137
137
p .isParameterOf ( callable , i ) and
138
138
p instanceof RelevantNode
@@ -142,8 +142,8 @@ private predicate viableParamCand(Call call, int i, ParameterNode p) {
142
142
/**
143
143
* Holds if `arg` is a possible argument to `p` taking virtual dispatch into account.
144
144
*/
145
- private predicate viableArgParamCand ( ArgumentNode arg , ParameterNode p ) {
146
- exists ( int i , DataFlowCall call |
145
+ private predicate viableArgParamCand ( DataFlowPrivate :: ArgumentNode arg , DataFlow :: ParameterNode p ) {
146
+ exists ( int i , DataFlowPrivate :: DataFlowCall call |
147
147
viableParamCand ( call .asCall ( ) , i , p ) and
148
148
arg .argumentOf ( call , i )
149
149
)
@@ -182,17 +182,20 @@ private predicate flowStep(RelevantNode n1, RelevantNode n2) {
182
182
v .getAUse ( ) = n2 .asExpr ( )
183
183
)
184
184
or
185
- exists ( Callable c | n1 .( InstanceParameterNode ) .getCallable ( ) = c |
185
+ exists ( Callable c | n1 .( DataFlow :: InstanceParameterNode ) .getCallable ( ) = c |
186
186
exists ( InstanceAccess ia |
187
187
ia = n2 .asExpr ( ) and ia .getEnclosingCallable ( ) = c and ia .isOwnInstanceAccess ( )
188
188
)
189
189
or
190
- n2 .( ImplicitInstanceAccess ) .getInstanceAccess ( ) .( OwnInstanceAccess ) .getEnclosingCallable ( ) = c
190
+ n2 .( DataFlow:: ImplicitInstanceAccess )
191
+ .getInstanceAccess ( )
192
+ .( OwnInstanceAccess )
193
+ .getEnclosingCallable ( ) = c
191
194
)
192
195
or
193
- n2 .( FieldValueNode ) .getField ( ) .getAnAssignedValue ( ) = n1 .asExpr ( )
196
+ n2 .( DataFlow :: FieldValueNode ) .getField ( ) .getAnAssignedValue ( ) = n1 .asExpr ( )
194
197
or
195
- n2 .asExpr ( ) .( FieldRead ) .getField ( ) = n1 .( FieldValueNode ) .getField ( )
198
+ n2 .asExpr ( ) .( FieldRead ) .getField ( ) = n1 .( DataFlow :: FieldValueNode ) .getField ( )
196
199
or
197
200
exists ( EnumType enum , Method getValue |
198
201
enum .getAnEnumConstant ( ) .getAnAssignedValue ( ) = n1 .asExpr ( ) and
@@ -214,7 +217,9 @@ private predicate flowStep(RelevantNode n1, RelevantNode n2) {
214
217
n2 .asExpr ( ) .( ArrayAccess ) .getArray ( ) = n1 .asExpr ( )
215
218
or
216
219
exists ( Argument arg |
217
- n1 .asExpr ( ) = arg and arg .isVararg ( ) and n2 .( ImplicitVarargsArray ) .getCall ( ) = arg .getCall ( )
220
+ n1 .asExpr ( ) = arg and
221
+ arg .isVararg ( ) and
222
+ n2 .( DataFlow:: ImplicitVarargsArray ) .getCall ( ) = arg .getCall ( )
218
223
)
219
224
or
220
225
exists ( AssignExpr a , Variable v |
@@ -255,37 +260,37 @@ private predicate flowStep(RelevantNode n1, RelevantNode n2) {
255
260
/**
256
261
* Holds if `n` is forward-reachable from a relevant `ClassInstanceExpr`.
257
262
*/
258
- private predicate nodeCandFwd ( Node n ) {
263
+ private predicate nodeCandFwd ( DataFlow :: Node n ) {
259
264
dispatchOrigin ( n .asExpr ( ) , _, _)
260
265
or
261
- exists ( Node mid | nodeCandFwd ( mid ) | flowStep ( mid , n ) or callFlowStepCand ( mid , n ) )
266
+ exists ( DataFlow :: Node mid | nodeCandFwd ( mid ) | flowStep ( mid , n ) or callFlowStepCand ( mid , n ) )
262
267
}
263
268
264
269
/**
265
270
* Holds if `n` may occur on a dispatch flow path. That is, a path from a
266
271
* relevant `ClassInstanceExpr` to a qualifier of a relevant `MethodAccess`.
267
272
*/
268
- private predicate nodeCand ( Node n ) {
273
+ private predicate nodeCand ( DataFlow :: Node n ) {
269
274
exists ( MethodAccess ma |
270
275
dispatchOrigin ( _, ma , _) and
271
- n = getInstanceArgument ( ma ) and
276
+ n = DataFlow :: getInstanceArgument ( ma ) and
272
277
nodeCandFwd ( n )
273
278
)
274
279
or
275
- exists ( Node mid | nodeCand ( mid ) | flowStep ( n , mid ) or callFlowStepCand ( n , mid ) ) and
280
+ exists ( DataFlow :: Node mid | nodeCand ( mid ) | flowStep ( n , mid ) or callFlowStepCand ( n , mid ) ) and
276
281
nodeCandFwd ( n )
277
282
}
278
283
279
284
/**
280
285
* Holds if `n1 -> n2` is a relevant dispatch flow step.
281
286
*/
282
- private predicate step ( Node n1 , Node n2 ) {
287
+ private predicate step ( DataFlow :: Node n1 , DataFlow :: Node n2 ) {
283
288
( flowStep ( n1 , n2 ) or callFlowStepCand ( n1 , n2 ) ) and
284
289
nodeCand ( n1 ) and
285
290
nodeCand ( n2 )
286
291
}
287
292
288
- private predicate stepPlus ( Node n1 , Node n2 ) = fastTC( step / 2 ) ( n1 , n2 )
293
+ private predicate stepPlus ( DataFlow :: Node n1 , DataFlow :: Node n2 ) = fastTC( step / 2 ) ( n1 , n2 )
289
294
290
295
/**
291
296
* Holds if there is flow from a `ClassInstanceExpr` instantiating a type that
@@ -296,7 +301,7 @@ pragma[inline]
296
301
private predicate hasDispatchFlow ( MethodAccess ma , Method m ) {
297
302
exists ( ClassInstanceExpr cie |
298
303
dispatchOrigin ( cie , ma , m ) and
299
- stepPlus ( exprNode ( cie ) , getInstanceArgument ( ma ) )
304
+ stepPlus ( DataFlow :: exprNode ( cie ) , DataFlow :: getInstanceArgument ( ma ) )
300
305
)
301
306
}
302
307
0 commit comments