@@ -3,9 +3,7 @@ private import semmle.code.java.dataflow.DataFlow
33private import semmle.code.java.dataflow.ExternalFlow
44private import semmle.code.java.dataflow.FlowSteps
55
6- /**
7- * The class `android.content.Intent`.
8- */
6+ /** The class `android.content.Intent`. */
97class TypeIntent extends Class {
108 TypeIntent ( ) { this .hasQualifiedName ( "android.content" , "Intent" ) }
119}
@@ -15,66 +13,43 @@ class TypeComponentName extends Class {
1513 TypeComponentName ( ) { this .hasQualifiedName ( "android.content" , "ComponentName" ) }
1614}
1715
18- /**
19- * The class `android.app.Activity`.
20- */
16+ /** The class `android.app.Activity`. */
2117class TypeActivity extends Class {
2218 TypeActivity ( ) { this .hasQualifiedName ( "android.app" , "Activity" ) }
2319}
2420
25- /**
26- * The class `android.app.Service`.
27- */
21+ /** The class `android.app.Service`. */
2822class TypeService extends Class {
2923 TypeService ( ) { this .hasQualifiedName ( "android.app" , "Service" ) }
3024}
3125
32- /**
33- * The class `android.content.Context`.
34- */
26+ /** The class `android.content.Context`. */
3527class TypeContext extends RefType {
3628 // Not inlining this makes it more likely to be used as a sentinel,
3729 // which is useful when running Android queries on non-Android projects.
3830 pragma [ noinline]
3931 TypeContext ( ) { this .hasQualifiedName ( "android.content" , "Context" ) }
4032}
4133
42- /**
43- * The class `android.content.BroadcastReceiver`.
44- */
34+ /** The class `android.content.BroadcastReceiver`. */
4535class TypeBroadcastReceiver extends Class {
4636 TypeBroadcastReceiver ( ) { this .hasQualifiedName ( "android.content" , "BroadcastReceiver" ) }
4737}
4838
49- /**
50- * The method `Activity.getIntent`
51- */
39+ /** The method `Activity.getIntent` */
5240class AndroidGetIntentMethod extends Method {
5341 AndroidGetIntentMethod ( ) {
5442 this .hasName ( "getIntent" ) and this .getDeclaringType ( ) instanceof TypeActivity
5543 }
5644}
5745
58- /**
59- * The method `BroadcastReceiver.onReceive`.
60- */
46+ /** The method `BroadcastReceiver.onReceive`. */
6147class AndroidReceiveIntentMethod extends Method {
6248 AndroidReceiveIntentMethod ( ) {
6349 this .hasName ( "onReceive" ) and this .getDeclaringType ( ) instanceof TypeBroadcastReceiver
6450 }
6551}
6652
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-
7853/**
7954 * The method `Service.onStart`, `onStartCommand`,
8055 * `onBind`, `onRebind`, `onUnbind`, or `onTaskRemoved`.
@@ -135,22 +110,21 @@ class SendBroadcastMethod extends Method {
135110 */
136111class StartServiceMethod extends Method {
137112 StartServiceMethod ( ) {
138- this .getName ( ) .matches ( [ "start%Service" , "bind%Service%" ] ) and
113+ this .hasName ( [
114+ "startService" , "startForegroundService" , "bindIsolatedService" , "bindService" ,
115+ "bindServiceAsUser"
116+ ] ) and
139117 this .getDeclaringType ( ) instanceof TypeContext
140118 }
141119}
142120
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. */
146122private class IntentFieldsInheritTaint extends DataFlow:: SyntheticFieldContent ,
147123 TaintInheritingContent {
148124 IntentFieldsInheritTaint ( ) { this .getField ( ) .matches ( "android.content.Intent.%" ) }
149125}
150126
151- /**
152- * The method `Intent.getParcelableExtra`.
153- */
127+ /** The method `Intent.getParcelableExtra`. */
154128class IntentGetParcelableExtraMethod extends Method {
155129 IntentGetParcelableExtraMethod ( ) {
156130 this .hasName ( "getParcelableExtra" ) and
@@ -212,9 +186,7 @@ private class BundleExtrasSyntheticField extends SyntheticField {
212186 override RefType getType ( ) { result instanceof AndroidBundle }
213187}
214188
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`. */
218190predicate allowIntentExtrasImplicitRead ( DataFlow:: Node node , DataFlow:: Content c ) {
219191 node .getType ( ) instanceof TypeIntent and
220192 (
@@ -283,26 +255,20 @@ private class StartComponentMethodAccess extends MethodAccess {
283255 }
284256}
285257
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-
300258/**
301259 * A value-preserving step from the intent argument of a `startActivity` call to
302260 * a `getIntent` call in the activity the intent targeted in its constructor.
303261 */
304262private 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+ }
306272}
307273
308274/**
0 commit comments