@@ -3,9 +3,7 @@ private import semmle.code.java.dataflow.DataFlow
3
3
private import semmle.code.java.dataflow.ExternalFlow
4
4
private import semmle.code.java.dataflow.FlowSteps
5
5
6
- /**
7
- * The class `android.content.Intent`.
8
- */
6
+ /** The class `android.content.Intent`. */
9
7
class TypeIntent extends Class {
10
8
TypeIntent ( ) { this .hasQualifiedName ( "android.content" , "Intent" ) }
11
9
}
@@ -15,66 +13,43 @@ class TypeComponentName extends Class {
15
13
TypeComponentName ( ) { this .hasQualifiedName ( "android.content" , "ComponentName" ) }
16
14
}
17
15
18
- /**
19
- * The class `android.app.Activity`.
20
- */
16
+ /** The class `android.app.Activity`. */
21
17
class TypeActivity extends Class {
22
18
TypeActivity ( ) { this .hasQualifiedName ( "android.app" , "Activity" ) }
23
19
}
24
20
25
- /**
26
- * The class `android.app.Service`.
27
- */
21
+ /** The class `android.app.Service`. */
28
22
class TypeService extends Class {
29
23
TypeService ( ) { this .hasQualifiedName ( "android.app" , "Service" ) }
30
24
}
31
25
32
- /**
33
- * The class `android.content.Context`.
34
- */
26
+ /** The class `android.content.Context`. */
35
27
class TypeContext extends RefType {
36
28
// Not inlining this makes it more likely to be used as a sentinel,
37
29
// which is useful when running Android queries on non-Android projects.
38
30
pragma [ noinline]
39
31
TypeContext ( ) { this .hasQualifiedName ( "android.content" , "Context" ) }
40
32
}
41
33
42
- /**
43
- * The class `android.content.BroadcastReceiver`.
44
- */
34
+ /** The class `android.content.BroadcastReceiver`. */
45
35
class TypeBroadcastReceiver extends Class {
46
36
TypeBroadcastReceiver ( ) { this .hasQualifiedName ( "android.content" , "BroadcastReceiver" ) }
47
37
}
48
38
49
- /**
50
- * The method `Activity.getIntent`
51
- */
39
+ /** The method `Activity.getIntent` */
52
40
class AndroidGetIntentMethod extends Method {
53
41
AndroidGetIntentMethod ( ) {
54
42
this .hasName ( "getIntent" ) and this .getDeclaringType ( ) instanceof TypeActivity
55
43
}
56
44
}
57
45
58
- /**
59
- * The method `BroadcastReceiver.onReceive`.
60
- */
46
+ /** The method `BroadcastReceiver.onReceive`. */
61
47
class AndroidReceiveIntentMethod extends Method {
62
48
AndroidReceiveIntentMethod ( ) {
63
49
this .hasName ( "onReceive" ) and this .getDeclaringType ( ) instanceof TypeBroadcastReceiver
64
50
}
65
51
}
66
52
67
- /**
68
- * The method `Service.onStart`, `onStartCommand`,
69
- * `onBind`, `onRebind`, `onUnbind`, or `onTaskRemoved`.
70
- */
71
- class AndroidServiceIntentMethod extends Method {
72
- AndroidServiceIntentMethod ( ) {
73
- this .getName ( ) .matches ( [ "onStart%" , "on%ind" , "onTaskRemoved" ] ) and
74
- this .getDeclaringType ( ) instanceof TypeService
75
- }
76
- }
77
-
78
53
/**
79
54
* The method `Service.onStart`, `onStartCommand`,
80
55
* `onBind`, `onRebind`, `onUnbind`, or `onTaskRemoved`.
@@ -135,22 +110,21 @@ class SendBroadcastMethod extends Method {
135
110
*/
136
111
class StartServiceMethod extends Method {
137
112
StartServiceMethod ( ) {
138
- this .getName ( ) .matches ( [ "start%Service" , "bind%Service%" ] ) and
113
+ this .hasName ( [
114
+ "startService" , "startForegroundService" , "bindIsolatedService" , "bindService" ,
115
+ "bindServiceAsUser"
116
+ ] ) and
139
117
this .getDeclaringType ( ) instanceof TypeContext
140
118
}
141
119
}
142
120
143
- /**
144
- * Specifies that if an `Intent` is tainted, then so are its synthetic fields.
145
- */
121
+ /** Specifies that if an `Intent` is tainted, then so are its synthetic fields. */
146
122
private class IntentFieldsInheritTaint extends DataFlow:: SyntheticFieldContent ,
147
123
TaintInheritingContent {
148
124
IntentFieldsInheritTaint ( ) { this .getField ( ) .matches ( "android.content.Intent.%" ) }
149
125
}
150
126
151
- /**
152
- * The method `Intent.getParcelableExtra`.
153
- */
127
+ /** The method `Intent.getParcelableExtra`. */
154
128
class IntentGetParcelableExtraMethod extends Method {
155
129
IntentGetParcelableExtraMethod ( ) {
156
130
this .hasName ( "getParcelableExtra" ) and
@@ -212,9 +186,7 @@ private class BundleExtrasSyntheticField extends SyntheticField {
212
186
override RefType getType ( ) { result instanceof AndroidBundle }
213
187
}
214
188
215
- /**
216
- * Holds if extras may be implicitly read from the Intent `node`.
217
- */
189
+ /** Holds if extras may be implicitly read from the Intent `node`. */
218
190
predicate allowIntentExtrasImplicitRead ( DataFlow:: Node node , DataFlow:: Content c ) {
219
191
node .getType ( ) instanceof TypeIntent and
220
192
(
@@ -283,26 +255,20 @@ private class StartComponentMethodAccess extends MethodAccess {
283
255
}
284
256
}
285
257
286
- /**
287
- * Holds if there is a step from the intent argument `n1` of a `startActivity` call
288
- * to a `getIntent` call `n2` in the activity `n1` targets.
289
- */
290
- private predicate startActivityIntentStep ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
291
- exists ( StartComponentMethodAccess startActivity , MethodAccess getIntent |
292
- startActivity .getMethod ( ) .overrides * ( any ( StartActivityMethod m ) ) and
293
- getIntent .getMethod ( ) .overrides * ( any ( AndroidGetIntentMethod m ) ) and
294
- startActivity .targetsComponentType ( getIntent .getReceiverType ( ) ) and
295
- n1 .asExpr ( ) = startActivity .getIntentArg ( ) and
296
- n2 .asExpr ( ) = getIntent
297
- )
298
- }
299
-
300
258
/**
301
259
* A value-preserving step from the intent argument of a `startActivity` call to
302
260
* a `getIntent` call in the activity the intent targeted in its constructor.
303
261
*/
304
262
private class StartActivityIntentStep extends AdditionalValueStep {
305
- override predicate step ( DataFlow:: Node n1 , DataFlow:: Node n2 ) { startActivityIntentStep ( n1 , n2 ) }
263
+ override predicate step ( DataFlow:: Node n1 , DataFlow:: Node n2 ) {
264
+ exists ( StartComponentMethodAccess startActivity , MethodAccess getIntent |
265
+ startActivity .getMethod ( ) .overrides * ( any ( StartActivityMethod m ) ) and
266
+ getIntent .getMethod ( ) .overrides * ( any ( AndroidGetIntentMethod m ) ) and
267
+ startActivity .targetsComponentType ( getIntent .getReceiverType ( ) ) and
268
+ n1 .asExpr ( ) = startActivity .getIntentArg ( ) and
269
+ n2 .asExpr ( ) = getIntent
270
+ )
271
+ }
306
272
}
307
273
308
274
/**
0 commit comments