Skip to content

Commit 66b3c46

Browse files
Jami Cogswellatorralba
authored andcommitted
resolve merge conflict
1 parent 0a135a7 commit 66b3c46

File tree

5 files changed

+43
-187
lines changed

5 files changed

+43
-187
lines changed

java/ql/lib/semmle/code/java/frameworks/android/Intent.qll

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ private import semmle.code.java.dataflow.DataFlow
33
private import semmle.code.java.dataflow.ExternalFlow
44
private import semmle.code.java.dataflow.FlowSteps
55

6-
// ! Remember to add 'private' annotation as needed to new classes/predicates below.
7-
// ! and clean-up comments, etc. in below in general before marking as ready-for-review.
86
/**
97
* The class `android.content.Intent`.
108
*/
@@ -66,21 +64,13 @@ class AndroidReceiveIntentMethod extends Method {
6664
}
6765
}
6866

69-
// ! not sure if I like the name of the below class, but
70-
// ! trying to be consistent with `AndroidReceiveIntentMethod`
71-
// ! and `AndroidGetIntentMethod`...
7267
/**
73-
* A method of type Service that receives an Intent.
74-
* Namely, `Service.onStart`, `onStartCommand`, `onBind`,
75-
* `onRebind`, `onUnbind`, or `onTaskRemoved`
68+
* The method `Service.onStart`, `onStartCommand`,
69+
* `onBind`, `onRebind`, `onUnbind`, or `onTaskRemoved`.
7670
*/
7771
class AndroidServiceIntentMethod extends Method {
7872
AndroidServiceIntentMethod() {
79-
(
80-
this.getName().matches("onStart%") or
81-
this.getName().matches("on%ind") or
82-
this.hasName("onTaskRemoved")
83-
) and
73+
this.getName().matches(["onStart%", "on%ind", "onTaskRemoved"]) and
8474
this.getDeclaringType() instanceof TypeService
8575
}
8676
}
@@ -127,20 +117,13 @@ class SendBroadcastMethod extends Method {
127117
}
128118
}
129119

130-
// ! remove reference from below QLDoc?
131120
/**
132121
* The method `Context.startService`, `startForegroundService`,
133122
* `bindIsolatedService`, `bindService`, or `bindServiceAsUser`.
134-
*
135-
* From https://developer.android.com/reference/android/app/Service:
136-
* "Services can be started with Context.startService() and Context.bindService()."
137123
*/
138124
class StartServiceMethod extends Method {
139125
StartServiceMethod() {
140-
(
141-
this.getName().matches("start%Service") or
142-
this.getName().matches("bind%Service%")
143-
) and
126+
this.getName().matches(["start%Service", "bind%Service%"]) and
144127
this.getDeclaringType() instanceof TypeContext
145128
}
146129
}
@@ -254,25 +237,6 @@ class GrantWriteUriPermissionFlag extends GrantUriPermissionFlag {
254237
GrantWriteUriPermissionFlag() { this.hasName("FLAG_GRANT_WRITE_URI_PERMISSION") }
255238
}
256239

257-
// ! OLD VERSION - need to delete - keeping for now for reference
258-
// /**
259-
// * A value-preserving step from the Intent argument of a `startActivity` call to
260-
// * a `getIntent` call in the Activity the Intent pointed to in its constructor.
261-
// */
262-
// private class StartActivityIntentStep extends AdditionalValueStep {
263-
// override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
264-
// exists(MethodAccess startActivity, MethodAccess getIntent, ClassInstanceExpr newIntent |
265-
// startActivity.getMethod().overrides*(any(ContextStartActivityMethod m)) and
266-
// getIntent.getMethod().overrides*(any(AndroidGetIntentMethod m)) and
267-
// newIntent.getConstructedType() instanceof TypeIntent and
268-
// DataFlow::localExprFlow(newIntent, startActivity.getArgument(0)) and
269-
// newIntent.getArgument(1).getType().(ParameterizedType).getATypeArgument() =
270-
// getIntent.getReceiverType() and
271-
// n1.asExpr() = startActivity.getArgument(0) and
272-
// n2.asExpr() = getIntent
273-
// )
274-
// }
275-
// }
276240
/*
277241
* // ! TODO: create a parent class for the below three steps?
278242
* // ! e.g. something like the below?
@@ -283,9 +247,13 @@ class GrantWriteUriPermissionFlag extends GrantUriPermissionFlag {
283247
* // class StartComponentIntentStep extends AdditionalValueStep { }
284248
*/
285249

286-
// The `android.Content.Intent` class has two constructors with an argument of type
287-
// `Class<?>`. One has the argument at position 1 and the other at position 3.
288-
// https://developer.android.com/reference/android/content/Intent#public-constructors
250+
/**
251+
* Gets the `Class<?>` argument of an `android.content.Intent`constructor.
252+
*
253+
* The `android.content.Intent` class has two constructors with an argument of type
254+
* `Class<?>`. One has the argument at position 1 and the other at position 3.
255+
* https://developer.android.com/reference/android/content/Intent#public-constructors
256+
*/
289257
private Argument getClassArgOfIntentConstructor(ClassInstanceExpr classInstanceExpr) {
290258
classInstanceExpr.getConstructedType() instanceof TypeIntent and
291259
if classInstanceExpr.getNumArgument() = 2
@@ -298,9 +266,13 @@ private Argument getClassArgOfIntentConstructor(ClassInstanceExpr classInstanceE
298266
* a `getIntent` call in the Activity the Intent pointed to in its constructor.
299267
*/
300268
private class StartActivityIntentStep extends AdditionalValueStep {
301-
// The `startActivityFromChild` and `startActivityFromFragment` methods have
302-
// an argument of type `Intent` at position 1, but the rest of the methods of
303-
// type `StartActivityMethod` have an argument of type `Intent` at position 0.
269+
/**
270+
* Gets the `Intent` argument of an Android `StartActivityMethod`.
271+
*
272+
* The `startActivityFromChild` and `startActivityFromFragment` methods have
273+
* an argument of type `Intent` at position 1, but the rest of the methods of
274+
* type `StartActivityMethod` have an argument of type `Intent` at position 0.
275+
*/
304276
private Argument getIntentArgOfStartActMethod(MethodAccess methodAccess) {
305277
methodAccess.getMethod().overrides*(any(StartActivityMethod m)) and
306278
if
@@ -310,15 +282,6 @@ private class StartActivityIntentStep extends AdditionalValueStep {
310282
else result = methodAccess.getArgument(0)
311283
}
312284

313-
// // The `android.Content.Intent` class has two constructors with an argument of type
314-
// // `Class<?>`. One has the argument at position 1 and the other at position 3.
315-
// // https://developer.android.com/reference/android/content/Intent#public-constructors
316-
// private Argument getClassArgOfIntentConstructor(ClassInstanceExpr classInstanceExpr) {
317-
// classInstanceExpr.getConstructedType() instanceof TypeIntent and
318-
// if classInstanceExpr.getNumArgument() = 2
319-
// then result = classInstanceExpr.getArgument(1)
320-
// else result = classInstanceExpr.getArgument(3)
321-
// }
322285
override predicate step(DataFlow::Node n1, DataFlow::Node n2) {
323286
exists(MethodAccess startActivity, MethodAccess getIntent, ClassInstanceExpr newIntent |
324287
startActivity.getMethod().overrides*(any(StartActivityMethod m)) and
@@ -353,7 +316,6 @@ private class SendBroadcastReceiverIntentStep extends AdditionalValueStep {
353316
}
354317
}
355318

356-
// ! potentially reword QLDoc
357319
/**
358320
* A value-preserving step from the Intent argument of a `startService` call to
359321
* the `Intent` parameter in an `AndroidServiceIntentMethod` of the Service the

java/ql/lib/semmle/code/java/security/DeepLink.qll

Lines changed: 0 additions & 50 deletions
This file was deleted.

java/ql/test/library-tests/frameworks/android/intent/AndroidManifest.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,30 @@
1818
android:exported="false">
1919
</activity>
2020

21+
<activity
22+
android:name=".TestStartActivityToGetIntent.SafeActivity"
23+
android:exported="false">
24+
</activity>
25+
26+
<service
27+
android:name=".TestStartServiceToGetIntent.SomeService"
28+
android:exported="false">
29+
</service>
30+
31+
<service
32+
android:name=".TestStartServiceToGetIntent.SafeService"
33+
android:exported="false">
34+
</service>
35+
36+
<receiver
37+
android:name=".TestStartBroadcastReceiverToGetIntent.SomeBroadcastReceiver"
38+
android:exported="false">
39+
</receiver>
40+
41+
<receiver
42+
android:name=".TestStartBroadcastReceiverToGetIntent.SafeBroadcastReceiver"
43+
android:exported="false">
44+
</receiver>
45+
2146
</application>
2247
</manifest>

java/ql/test/library-tests/frameworks/android/intent/TestStartActivityToGetIntent.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,6 @@
22
import android.content.Context;
33
import android.content.Intent;
44

5-
// ! Original - saving for reference
6-
// public class TestStartActivityToGetIntent {
7-
8-
// static Object source() {
9-
// return null;
10-
// }
11-
12-
// static void sink(Object sink) {
13-
// }
14-
15-
// public void test(Context ctx) {
16-
// Intent intent = new Intent(null, SomeActivity.class);
17-
// intent.putExtra("data", (String) source());
18-
// ctx.startActivity(intent);
19-
// }
20-
21-
// static class SomeActivity extends Activity {
22-
23-
// public void test() {
24-
// sink(getIntent().getStringExtra("data")); // $ hasValueFlow
25-
// }
26-
// }
27-
// }
28-
295
public class TestStartActivityToGetIntent {
306

317
static Object source(String kind) {

java/ql/test/library-tests/frameworks/android/intent/TestStartComponentToIntent.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)