2
2
* Provides predicates related to capturing summary models of the Standard or a 3rd party library.
3
3
*/
4
4
5
- import java
5
+ private import java as J
6
6
private import semmle.code.java.dataflow.internal.DataFlowNodes
7
7
private import semmle.code.java.dataflow.internal.DataFlowPrivate
8
- private import semmle.code.java.dataflow.InstanceAccess
9
- private import semmle.code.java.dataflow.internal.ContainerFlow
10
- import semmle.code.java.dataflow.TaintTracking
8
+ private import semmle.code.java.dataflow.internal.ContainerFlow as ContainerFlow
11
9
import semmle.code.java.dataflow.ExternalFlow as ExternalFlow
12
10
import semmle.code.java.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
13
11
import semmle.code.java.dataflow.internal.DataFlowPrivate as DataFlowPrivate
14
12
15
- private Method superImpl ( Method m ) {
13
+ module DataFlow = J:: DataFlow;
14
+
15
+ module TaintTracking = J:: TaintTracking;
16
+
17
+ class Type = J:: Type ;
18
+
19
+ private J:: Method superImpl ( J:: Method m ) {
16
20
result = m .getAnOverride ( ) and
17
21
not exists ( result .getAnOverride ( ) ) and
18
- not m instanceof ToStringMethod
22
+ not m instanceof J :: ToStringMethod
19
23
}
20
24
21
- private predicate isInTestFile ( File file ) {
25
+ private predicate isInTestFile ( J :: File file ) {
22
26
file .getAbsolutePath ( ) .matches ( "%src/test/%" ) or
23
27
file .getAbsolutePath ( ) .matches ( "%/guava-tests/%" ) or
24
28
file .getAbsolutePath ( ) .matches ( "%/guava-testlib/%" )
25
29
}
26
30
27
- private predicate isJdkInternal ( CompilationUnit cu ) {
31
+ private predicate isJdkInternal ( J :: CompilationUnit cu ) {
28
32
cu .getPackage ( ) .getName ( ) .matches ( "org.graalvm%" ) or
29
33
cu .getPackage ( ) .getName ( ) .matches ( "com.sun%" ) or
30
34
cu .getPackage ( ) .getName ( ) .matches ( "javax.swing%" ) or
@@ -46,10 +50,10 @@ private predicate isJdkInternal(CompilationUnit cu) {
46
50
/**
47
51
* Holds if it is relevant to generate models for `api`.
48
52
*/
49
- private predicate isRelevantForModels ( Callable api ) {
53
+ private predicate isRelevantForModels ( J :: Callable api ) {
50
54
not isInTestFile ( api .getCompilationUnit ( ) .getFile ( ) ) and
51
55
not isJdkInternal ( api .getCompilationUnit ( ) ) and
52
- not api instanceof MainMethod
56
+ not api instanceof J :: MainMethod
53
57
}
54
58
55
59
/**
@@ -58,7 +62,7 @@ private predicate isRelevantForModels(Callable api) {
58
62
* In the Standard library and 3rd party libraries it the Callables that can be called
59
63
* from outside the library itself.
60
64
*/
61
- class TargetApiSpecific extends Callable {
65
+ class TargetApiSpecific extends J :: Callable {
62
66
TargetApiSpecific ( ) {
63
67
this .isPublic ( ) and
64
68
this .fromSource ( ) and
@@ -70,15 +74,15 @@ class TargetApiSpecific extends Callable {
70
74
}
71
75
}
72
76
73
- private string isExtensible ( RefType ref ) {
77
+ private string isExtensible ( J :: RefType ref ) {
74
78
if ref .isFinal ( ) then result = "false" else result = "true"
75
79
}
76
80
77
- private string typeAsModel ( RefType type ) {
81
+ private string typeAsModel ( J :: RefType type ) {
78
82
result = type .getCompilationUnit ( ) .getPackage ( ) .getName ( ) + ";" + type .nestedName ( )
79
83
}
80
84
81
- private RefType bestTypeForModel ( TargetApiSpecific api ) {
85
+ private J :: RefType bestTypeForModel ( TargetApiSpecific api ) {
82
86
if exists ( superImpl ( api ) )
83
87
then superImpl ( api ) .fromSource ( ) and result = superImpl ( api ) .getDeclaringType ( )
84
88
else result = api .getDeclaringType ( )
@@ -104,42 +108,42 @@ string asPartialModel(TargetApiSpecific api) {
104
108
+ /* ext + */ ";" //
105
109
}
106
110
107
- private predicate isPrimitiveTypeUsedForBulkData ( Type t ) {
111
+ private predicate isPrimitiveTypeUsedForBulkData ( J :: Type t ) {
108
112
t .getName ( ) .regexpMatch ( "byte|char|Byte|Character" )
109
113
}
110
114
111
115
/**
112
116
* Holds for type `t` for fields that are relevant as an intermediate
113
117
* read or write step in the data flow analysis.
114
118
*/
115
- predicate isRelevantType ( Type t ) {
116
- not t instanceof TypeClass and
117
- not t instanceof EnumType and
118
- not t instanceof PrimitiveType and
119
- not t instanceof BoxedType and
120
- not t .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.lang" , "Number" ) and
121
- not t .( RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.nio.charset" , "Charset" ) and
119
+ predicate isRelevantType ( J :: Type t ) {
120
+ not t instanceof J :: TypeClass and
121
+ not t instanceof J :: EnumType and
122
+ not t instanceof J :: PrimitiveType and
123
+ not t instanceof J :: BoxedType and
124
+ not t .( J :: RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.lang" , "Number" ) and
125
+ not t .( J :: RefType ) .getAnAncestor ( ) .hasQualifiedName ( "java.nio.charset" , "Charset" ) and
122
126
(
123
- not t .( Array ) .getElementType ( ) instanceof PrimitiveType or
124
- isPrimitiveTypeUsedForBulkData ( t .( Array ) .getElementType ( ) )
127
+ not t .( J :: Array ) .getElementType ( ) instanceof J :: PrimitiveType or
128
+ isPrimitiveTypeUsedForBulkData ( t .( J :: Array ) .getElementType ( ) )
125
129
) and
126
130
(
127
- not t .( Array ) .getElementType ( ) instanceof BoxedType or
128
- isPrimitiveTypeUsedForBulkData ( t .( Array ) .getElementType ( ) )
131
+ not t .( J :: Array ) .getElementType ( ) instanceof J :: BoxedType or
132
+ isPrimitiveTypeUsedForBulkData ( t .( J :: Array ) .getElementType ( ) )
129
133
) and
130
134
(
131
- not t .( CollectionType ) .getElementType ( ) instanceof BoxedType or
132
- isPrimitiveTypeUsedForBulkData ( t .( CollectionType ) .getElementType ( ) )
135
+ not t .( ContainerFlow :: CollectionType ) .getElementType ( ) instanceof J :: BoxedType or
136
+ isPrimitiveTypeUsedForBulkData ( t .( ContainerFlow :: CollectionType ) .getElementType ( ) )
133
137
)
134
138
}
135
139
136
- private string parameterAccess ( Parameter p ) {
140
+ private string parameterAccess ( J :: Parameter p ) {
137
141
if
138
- p .getType ( ) instanceof Array and
139
- not isPrimitiveTypeUsedForBulkData ( p .getType ( ) .( Array ) .getElementType ( ) )
142
+ p .getType ( ) instanceof J :: Array and
143
+ not isPrimitiveTypeUsedForBulkData ( p .getType ( ) .( J :: Array ) .getElementType ( ) )
140
144
then result = "Argument[" + p .getPosition ( ) + "].ArrayElement"
141
145
else
142
- if p .getType ( ) instanceof ContainerType
146
+ if p .getType ( ) instanceof ContainerFlow :: ContainerType
143
147
then result = "Argument[" + p .getPosition ( ) + "].Element"
144
148
else result = "Argument[" + p .getPosition ( ) + "]"
145
149
}
@@ -172,15 +176,15 @@ string returnNodeAsOutput(DataFlowImplCommon::ReturnNodeExt node) {
172
176
/**
173
177
* Gets the enclosing callable of `ret`.
174
178
*/
175
- Callable returnNodeEnclosingCallable ( DataFlowImplCommon:: ReturnNodeExt ret ) {
179
+ J :: Callable returnNodeEnclosingCallable ( DataFlowImplCommon:: ReturnNodeExt ret ) {
176
180
result = DataFlowImplCommon:: getNodeEnclosingCallable ( ret ) .asCallable ( )
177
181
}
178
182
179
183
/**
180
184
* Holds if `node` is an own instance access.
181
185
*/
182
186
predicate isOwnInstanceAccessNode ( ReturnNode node ) {
183
- node .asExpr ( ) .( ThisAccess ) .isOwnInstanceAccess ( )
187
+ node .asExpr ( ) .( J :: ThisAccess ) .isOwnInstanceAccess ( )
184
188
}
185
189
186
190
/**
@@ -195,11 +199,14 @@ class PropagateToSinkConfigurationSpecific extends TaintTracking::Configuration
195
199
PropagateToSinkConfigurationSpecific ( ) { this = "parameters or fields flowing into sinks" }
196
200
197
201
override predicate isSource ( DataFlow:: Node source ) {
198
- ( source .asExpr ( ) .( FieldAccess ) .isOwnFieldAccess ( ) or source instanceof DataFlow:: ParameterNode ) and
202
+ (
203
+ source .asExpr ( ) .( J:: FieldAccess ) .isOwnFieldAccess ( ) or
204
+ source instanceof DataFlow:: ParameterNode
205
+ ) and
199
206
source .getEnclosingCallable ( ) .isPublic ( ) and
200
- exists ( RefType t |
207
+ exists ( J :: RefType t |
201
208
t = source .getEnclosingCallable ( ) .getDeclaringType ( ) .getAnAncestor ( ) and
202
- not t instanceof TypeObject and
209
+ not t instanceof J :: TypeObject and
203
210
t .isPublic ( )
204
211
) and
205
212
isRelevantForModels ( source .getEnclosingCallable ( ) )
@@ -215,7 +222,7 @@ string asInputArgument(DataFlow::Node source) {
215
222
result = "Argument[" + pos + "]"
216
223
)
217
224
or
218
- source .asExpr ( ) instanceof FieldAccess and
225
+ source .asExpr ( ) instanceof J :: FieldAccess and
219
226
result = qualifierString ( )
220
227
}
221
228
0 commit comments