2
2
3
3
import java
4
4
import semmle.code.java.dataflow.DataFlow
5
+ import semmle.code.xml.AndroidManifest
6
+ import semmle.code.java.frameworks.android.Intent
5
7
6
8
/** An `onReceive` method of a `BroadcastReceiver` */
7
9
private class OnReceiveMethod extends Method {
8
- OnReceiveMethod ( ) {
9
- this .getASourceOverriddenMethod * ( )
10
- .hasQualifiedName ( "android.content" , "BroadcastReceiver" , "onReceive" )
11
- }
10
+ OnReceiveMethod ( ) { this .getASourceOverriddenMethod * ( ) instanceof AndroidReceiveIntentMethod }
12
11
13
12
/** Gets the parameter of this method that holds the received `Intent`. */
14
13
Parameter getIntentParameter ( ) { result = this .getParameter ( 1 ) }
@@ -31,7 +30,7 @@ private class VerifiedIntentConfig extends DataFlow::Configuration {
31
30
}
32
31
33
32
/** An `onReceive` method that doesn't verify the action of the intent it receives. */
34
- class UnverifiedOnReceiveMethod extends OnReceiveMethod {
33
+ private class UnverifiedOnReceiveMethod extends OnReceiveMethod {
35
34
UnverifiedOnReceiveMethod ( ) {
36
35
not any ( VerifiedIntentConfig c ) .hasFlow ( DataFlow:: parameterNode ( this .getIntentParameter ( ) ) , _)
37
36
}
@@ -62,21 +61,18 @@ class SystemActionName extends Top {
62
61
SystemActionName ( ) {
63
62
name = getASystemActionName ( ) and
64
63
(
65
- this .( StringLiteral ) . getValue ( ) = "android.intent.action." + name
64
+ this .( CompileTimeConstantExpr ) . getStringValue ( ) = "android.intent.action." + name
66
65
or
67
66
this .( FieldRead ) .getField ( ) .hasQualifiedName ( "android.content" , "Intent" , "ACTION_" + name )
68
67
or
69
- this .( XMLAttribute ) . getValue ( ) = "android.intent.action." + name
68
+ this .( AndroidActionXmlElement ) . getActionName ( ) = "android.intent.action." + name
70
69
)
71
70
}
72
71
73
72
/** Gets the name of the system intent that this expression or attribute represents. */
74
73
string getName ( ) { result = name }
75
74
76
- override string toString ( ) {
77
- result =
78
- [ this .( StringLiteral ) .toString ( ) , this .( FieldRead ) .toString ( ) , this .( XMLAttribute ) .toString ( ) ]
79
- }
75
+ override string toString ( ) { result = [ this .( Expr ) .toString ( ) , this .( XMLAttribute ) .toString ( ) ] }
80
76
}
81
77
82
78
/** A call to `Context.registerReceiver` */
@@ -138,17 +134,12 @@ private predicate registeredUnverifiedSystemReceiver(
138
134
139
135
/** Holds if the XML element `rec` declares a receiver `orm` to receive the system action named `sa` that doesn't verify intents it receives. */
140
136
private predicate xmlUnverifiedSystemReceiver (
141
- XMLElement rec , UnverifiedOnReceiveMethod orm , SystemActionName sa
137
+ AndroidReceiverXmlElement rec , UnverifiedOnReceiveMethod orm , SystemActionName sa
142
138
) {
143
- exists ( XMLElement filter , XMLElement action , Class ormty |
144
- rec .hasName ( "receiver" ) and
145
- filter .hasName ( "intent-filter" ) and
146
- action .hasName ( "action" ) and
147
- filter = rec .getAChild ( ) and
148
- action = filter .getAChild ( ) and
139
+ exists ( Class ormty |
149
140
ormty = orm .getDeclaringType ( ) and
150
- rec .getAttribute ( "name" ) . getValue ( ) = [ "." + ormty .getName ( ) , ormty .getQualifiedName ( ) ] and
151
- action . getAttribute ( "name" ) = sa
141
+ rec .getComponentName ( ) = [ "." + ormty .getName ( ) , ormty .getQualifiedName ( ) ] and
142
+ rec . getAnIntentFilterElement ( ) . getAnActionElement ( ) = sa
152
143
)
153
144
}
154
145
0 commit comments