Skip to content

Commit 8fcf00b

Browse files
committed
Test improvements
1 parent fa41656 commit 8fcf00b

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

java/ql/test/query-tests/security/CWE-094/APKInstallation.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,41 @@ public void installAPK(String path) {
1515
startActivity(intent);
1616
}
1717

18-
public void downloadAPK(String url) {
19-
// BAD: the url is not checked
20-
Intent intent = new Intent(Intent.ACTION_VIEW);
21-
intent.setDataAndType(Uri.parse(url), "application/vnd.android.package-archive");
22-
startActivity(intent);
23-
}
24-
25-
public void installAPK2() {
26-
String path = "file:///sdcard/Download/MyApp.apk";
27-
Intent intent = new Intent(Intent.ACTION_VIEW);
28-
intent.setType("application/vnd.android.package-archive");
29-
intent.setData(Uri.parse(path));
30-
startActivity(intent);
31-
}
32-
3318
public void installAPK3(String path) {
3419
Intent intent = new Intent(Intent.ACTION_VIEW);
3520
intent.setType(APK_MIMETYPE);
21+
// BAD: the path is not checked
3622
intent.setData(Uri.fromFile(new File(path)));
3723
startActivity(intent);
3824
}
3925

40-
public void installAPK4(String path) {
26+
public void installAPKFromExternalStorage(String path) {
27+
// BAD: file is from external storage
4128
File file = new File(Environment.getExternalStorageDirectory(), path);
4229
Intent intent = new Intent(Intent.ACTION_VIEW);
4330
intent.setDataAndType(Uri.fromFile(file), APK_MIMETYPE);
4431
startActivity(intent);
4532
}
4633

47-
public void installAPK5(String path) {
34+
public void installAPKFromExternalStorageWithActionInstallPackage(String path) {
35+
// BAD: file is from external storage
4836
File file = new File(Environment.getExternalStorageDirectory(), path);
4937
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
5038
intent.setData(Uri.fromFile(file));
5139
startActivity(intent);
5240
}
5341

54-
public void installAPK6(String path) {
42+
public void installAPKInstallPackageLiteral(String path) {
5543
File file = new File(Environment.getExternalStorageDirectory(), path);
5644
Intent intent = new Intent("android.intent.action.INSTALL_PACKAGE");
5745
intent.setData(Uri.fromFile(file));
5846
startActivity(intent);
5947
}
6048

61-
public void openWebsite() {
62-
Intent intent = new Intent(Intent.ACTION_VIEW);
63-
intent.setData(Uri.parse("http://www.example.com"));
64-
startActivity(intent);
65-
}
66-
6749
public void otherIntent(File file) {
6850
Intent intent = new Intent(this, OtherActivity.class);
6951
intent.setAction(Intent.ACTION_VIEW);
52+
// BAD: the file is from unknown source
7053
intent.setData(Uri.fromFile(file));
7154
}
7255
}

0 commit comments

Comments
 (0)