@@ -13,46 +13,55 @@ private import semmle.code.java.dispatch.VirtualDispatch
1313private import semmle.code.java.dataflow.internal.BaseSSA
1414private import semmle.code.java.controlflow.Guards
1515private import codeql.typeflow.TypeFlow
16+ private import codeql.typeflow.UniversalFlow as UniversalFlow
1617
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+ /** Provides the input types and predicates for instantiation of `UniversalFlow`. */
25+ module FlowStepsInput implements UniversalFlow:: UniversalFlowInput< Location > {
26+ private newtype TFlowNode =
1927 TField ( Field f ) { not f .getType ( ) instanceof PrimitiveType } or
2028 TSsa ( BaseSsaVariable ssa ) { not ssa .getSourceVariable ( ) .getType ( ) instanceof PrimitiveType } or
2129 TExpr ( Expr e ) or
2230 TMethod ( Method m ) { not m .getReturnType ( ) instanceof PrimitiveType }
2331
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-
3032 /**
3133 * A `Field`, `BaseSsaVariable`, `Expr`, or `Method`.
3234 */
33- class TypeFlowNode extends TTypeFlowNode {
35+ class FlowNode extends TFlowNode {
36+ /** Gets a textual representation of this element. */
3437 string toString ( ) {
3538 result = this .asField ( ) .toString ( ) or
3639 result = this .asSsa ( ) .toString ( ) or
3740 result = this .asExpr ( ) .toString ( ) or
3841 result = this .asMethod ( ) .toString ( )
3942 }
4043
44+ /** Gets the source location for this element. */
4145 Location getLocation ( ) {
4246 result = this .asField ( ) .getLocation ( ) or
4347 result = this .asSsa ( ) .getLocation ( ) or
4448 result = this .asExpr ( ) .getLocation ( ) or
4549 result = this .asMethod ( ) .getLocation ( )
4650 }
4751
52+ /** Gets the field corresponding to this node, if any. */
4853 Field asField ( ) { this = TField ( result ) }
4954
55+ /** Gets the SSA variable corresponding to this node, if any. */
5056 BaseSsaVariable asSsa ( ) { this = TSsa ( result ) }
5157
58+ /** Gets the expression corresponding to this node, if any. */
5259 Expr asExpr ( ) { this = TExpr ( result ) }
5360
61+ /** Gets the method corresponding to this node, if any. */
5462 Method asMethod ( ) { this = TMethod ( result ) }
5563
64+ /** Gets the type of this node. */
5665 RefType getType ( ) {
5766 result = this .asField ( ) .getType ( ) or
5867 result = this .asSsa ( ) .getSourceVariable ( ) .getType ( ) or
@@ -61,8 +70,6 @@ private module Input implements TypeFlowInput<Location> {
6170 }
6271 }
6372
64- class Type = RefType ;
65-
6673 private SrcCallable viableCallable_v1 ( Call c ) {
6774 result = viableImpl_v1 ( c )
6875 or
@@ -88,7 +95,7 @@ private module Input implements TypeFlowInput<Location> {
8895 *
8996 * For a given `n2`, this predicate must include all possible `n1` that can flow to `n2`.
9097 */
91- predicate step ( TypeFlowNode n1 , TypeFlowNode n2 ) {
98+ predicate step ( FlowNode n1 , FlowNode n2 ) {
9299 n2 .asExpr ( ) .( ChooseExpr ) .getAResultExpr ( ) = n1 .asExpr ( )
93100 or
94101 exists ( Field f , Expr e |
@@ -134,7 +141,7 @@ private module Input implements TypeFlowInput<Location> {
134141 /**
135142 * Holds if `null` is the only value that flows to `n`.
136143 */
137- predicate isNullValue ( TypeFlowNode n ) {
144+ predicate isNullValue ( FlowNode n ) {
138145 n .asExpr ( ) instanceof NullLiteral
139146 or
140147 exists ( LocalVariableDeclExpr decl |
@@ -144,11 +151,21 @@ private module Input implements TypeFlowInput<Location> {
144151 )
145152 }
146153
147- predicate isExcludedFromNullAnalysis ( TypeFlowNode n ) {
154+ predicate isExcludedFromNullAnalysis ( FlowNode n ) {
148155 // Fields that are never assigned a non-null value are probably set by
149156 // reflection and are thus not always null.
150157 exists ( n .asField ( ) )
151158 }
159+ }
160+
161+ private module Input implements TypeFlowInput< Location > {
162+ import FlowStepsInput
163+
164+ class TypeFlowNode = FlowNode ;
165+
166+ predicate isExcludedFromNullAnalysis = FlowStepsInput:: isExcludedFromNullAnalysis / 1 ;
167+
168+ class Type = RefType ;
152169
153170 predicate exactTypeBase ( TypeFlowNode n , RefType t ) {
154171 exists ( ClassInstanceExpr e |
0 commit comments