@@ -13,24 +13,25 @@ private import semmle.code.java.dispatch.VirtualDispatch
13
13
private import semmle.code.java.dataflow.internal.BaseSSA
14
14
private import semmle.code.java.controlflow.Guards
15
15
private import codeql.typeflow.TypeFlow
16
+ private import codeql.typeflow.UniversalFlow as UniversalFlow
16
17
17
- private module Input implements TypeFlowInput< Location > {
18
- private newtype TTypeFlowNode =
18
+ /** Gets `t` if it is a `RefType` or the boxed type if `t` is a primitive type. */
19
+ private RefType boxIfNeeded ( J:: Type t ) {
20
+ t .( PrimitiveType ) .getBoxedType ( ) = result or
21
+ result = t
22
+ }
23
+
24
+ module FlowStepsInput implements UniversalFlow:: UniversalFlowInput< Location > {
25
+ private newtype TFlowNode =
19
26
TField ( Field f ) { not f .getType ( ) instanceof PrimitiveType } or
20
27
TSsa ( BaseSsaVariable ssa ) { not ssa .getSourceVariable ( ) .getType ( ) instanceof PrimitiveType } or
21
28
TExpr ( Expr e ) or
22
29
TMethod ( Method m ) { not m .getReturnType ( ) instanceof PrimitiveType }
23
30
24
- /** Gets `t` if it is a `RefType` or the boxed type if `t` is a primitive type. */
25
- private RefType boxIfNeeded ( J:: Type t ) {
26
- t .( PrimitiveType ) .getBoxedType ( ) = result or
27
- result = t
28
- }
29
-
30
31
/**
31
32
* A `Field`, `BaseSsaVariable`, `Expr`, or `Method`.
32
33
*/
33
- class TypeFlowNode extends TTypeFlowNode {
34
+ class FlowNode extends TFlowNode {
34
35
string toString ( ) {
35
36
result = this .asField ( ) .toString ( ) or
36
37
result = this .asSsa ( ) .toString ( ) or
@@ -61,8 +62,6 @@ private module Input implements TypeFlowInput<Location> {
61
62
}
62
63
}
63
64
64
- class Type = RefType ;
65
-
66
65
private SrcCallable viableCallable_v1 ( Call c ) {
67
66
result = viableImpl_v1 ( c )
68
67
or
@@ -88,7 +87,7 @@ private module Input implements TypeFlowInput<Location> {
88
87
*
89
88
* For a given `n2`, this predicate must include all possible `n1` that can flow to `n2`.
90
89
*/
91
- predicate step ( TypeFlowNode n1 , TypeFlowNode n2 ) {
90
+ predicate step ( FlowNode n1 , FlowNode n2 ) {
92
91
n2 .asExpr ( ) .( ChooseExpr ) .getAResultExpr ( ) = n1 .asExpr ( )
93
92
or
94
93
exists ( Field f , Expr e |
@@ -134,7 +133,7 @@ private module Input implements TypeFlowInput<Location> {
134
133
/**
135
134
* Holds if `null` is the only value that flows to `n`.
136
135
*/
137
- predicate isNullValue ( TypeFlowNode n ) {
136
+ predicate isNullValue ( FlowNode n ) {
138
137
n .asExpr ( ) instanceof NullLiteral
139
138
or
140
139
exists ( LocalVariableDeclExpr decl |
@@ -144,11 +143,21 @@ private module Input implements TypeFlowInput<Location> {
144
143
)
145
144
}
146
145
147
- predicate isExcludedFromNullAnalysis ( TypeFlowNode n ) {
146
+ predicate isExcludedFromNullAnalysis ( FlowNode n ) {
148
147
// Fields that are never assigned a non-null value are probably set by
149
148
// reflection and are thus not always null.
150
149
exists ( n .asField ( ) )
151
150
}
151
+ }
152
+
153
+ private module Input implements TypeFlowInput< Location > {
154
+ import FlowStepsInput
155
+
156
+ class TypeFlowNode = FlowNode ;
157
+
158
+ predicate isExcludedFromNullAnalysis = FlowStepsInput:: isExcludedFromNullAnalysis / 1 ;
159
+
160
+ class Type = RefType ;
152
161
153
162
predicate exactTypeBase ( TypeFlowNode n , RefType t ) {
154
163
exists ( ClassInstanceExpr e |
0 commit comments