Skip to content

Commit d43242d

Browse files
committed
Added tests
1 parent d0077b8 commit d43242d

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

java/ql/test/query-tests/security/CWE-927/ImplicitPendingIntentsTest.expected

Whitespace-only changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.example.test;
2+
3+
import android.app.Activity;
4+
import android.app.PendingIntent;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
8+
public class ImplicitPendingIntentsTest {
9+
10+
public static void test(Context ctx) throws PendingIntent.CanceledException {
11+
{
12+
Intent baseIntent = new Intent();
13+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, baseIntent, 0);
14+
Intent fwdIntent = new Intent();
15+
fwdIntent.putExtra("fwdIntent", pi);
16+
ctx.startActivity(fwdIntent); // $hasTaintFlow
17+
ctx.startActivities(new Intent[] {fwdIntent}); // $hasTaintFlow
18+
ctx.startService(fwdIntent); // Safe
19+
ctx.sendBroadcast(fwdIntent); // $hasTaintFlow
20+
21+
fwdIntent.setPackage("a.safe.package"); // Sanitizer
22+
ctx.startActivity(fwdIntent); // Safe
23+
}
24+
25+
{
26+
Intent safeIntent = new Intent(ctx, Activity.class); // Sanitizer
27+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, safeIntent, 0);
28+
Intent fwdIntent = new Intent();
29+
fwdIntent.putExtra("fwdIntent", pi);
30+
ctx.startActivity(fwdIntent); // Safe
31+
}
32+
33+
{
34+
Intent safeIntent = new Intent();
35+
safeIntent.setClass(ctx, Object.class); // Sanitizer
36+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, safeIntent, 0);
37+
Intent fwdIntent = new Intent();
38+
fwdIntent.putExtra("fwdIntent", pi);
39+
ctx.startActivity(fwdIntent); // Safe
40+
}
41+
42+
{
43+
Intent baseIntent = new Intent();
44+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, baseIntent, 0);
45+
Intent fwdIntent = new Intent(ctx, Activity.class); // Sanitizer
46+
fwdIntent.putExtra("fwdIntent", pi);
47+
ctx.startActivity(fwdIntent); // Safe
48+
}
49+
50+
{
51+
Intent baseIntent = new Intent();
52+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, baseIntent, 0);
53+
Intent fwdIntent = new Intent();
54+
fwdIntent.setPackage("a.safe.package"); // Sanitizer
55+
fwdIntent.putExtra("fwdIntent", pi);
56+
ctx.startActivity(fwdIntent); // Safe
57+
}
58+
59+
{
60+
Intent baseIntent = new Intent();
61+
int flag = PendingIntent.FLAG_IMMUTABLE;
62+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, baseIntent, flag); // Sanitizer
63+
Intent fwdIntent = new Intent();
64+
fwdIntent.putExtra("fwdIntent", pi);
65+
ctx.startActivity(fwdIntent); // Safe
66+
}
67+
68+
{
69+
Intent baseIntent = new Intent();
70+
int flag = PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT;
71+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, baseIntent, flag); // Sanitizer
72+
Intent fwdIntent = new Intent();
73+
fwdIntent.putExtra("fwdIntent", pi);
74+
ctx.startActivity(fwdIntent); // $ SPURIOUS: $ hasTaintFlow
75+
}
76+
77+
}
78+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java
2+
import semmle.code.java.security.ImplicitPendingIntentsQuery
3+
import TestUtilities.InlineFlowTest
4+
5+
class ImplicitPendingIntentsTest extends InlineFlowTest {
6+
override DataFlow::Configuration getValueFlowConfig() { none() }
7+
8+
override DataFlow::Configuration getTaintFlowConfig() {
9+
result instanceof ImplicitPendingIntentStartConf
10+
}
11+
}

0 commit comments

Comments
 (0)