Skip to content

Commit 0c1f3ed

Browse files
committed
Add tests for ContentProvider sources
1 parent a811ab3 commit 0c1f3ed

File tree

5 files changed

+235
-0
lines changed

5 files changed

+235
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:versionCode="1"
5+
android:versionName="1.0"
6+
package="com.example.app">
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:label="@string/app_name"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
16+
<activity
17+
android:name=".MainActivity"
18+
android:icon="@drawable/ic_launcher"
19+
android:label="@string/app_name">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
26+
<provider
27+
android:name=".Test"
28+
android:authority="com.example.myapp.Test"
29+
android:exported="true" />
30+
</application>
31+
</manifest>
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
package com.example.app;
2+
3+
import java.io.FileNotFoundException;
4+
import android.content.ContentProvider;
5+
import android.content.ContentValues;
6+
import android.content.res.AssetFileDescriptor;
7+
import android.database.Cursor;
8+
import android.net.Uri;
9+
import android.os.Bundle;
10+
import android.os.CancellationSignal;
11+
import android.os.ParcelFileDescriptor;
12+
import android.os.RemoteException;
13+
14+
public class Test extends ContentProvider {
15+
16+
void sink(Object o) {}
17+
18+
// "android.content;ContentProvider;true;call;(String,String,String,Bundle);;Parameter[0..3];contentprovider",
19+
@Override
20+
public Bundle call(String authority, String method, String arg, Bundle extras) {
21+
sink(authority); // $ hasTaintFlow
22+
sink(method); // $ hasTaintFlow
23+
sink(arg); // $ hasTaintFlow
24+
sink(extras.get("some_key")); // $ hasTaintFlow
25+
return null;
26+
}
27+
28+
// "android.content;ContentProvider;true;call;(String,String,Bundle);;Parameter[0..2];contentprovider",
29+
public Bundle call(String method, String arg, Bundle extras) {
30+
sink(method); // $ hasTaintFlow
31+
sink(arg); // $ hasTaintFlow
32+
sink(extras.get("some_key")); // $ hasTaintFlow
33+
return null;
34+
}
35+
36+
// "android.content;ContentProvider;true;delete;(Uri,String,String[]);;Parameter[0..2];contentprovider",
37+
@Override
38+
public int delete(Uri uri, String selection, String[] selectionArgs) {
39+
sink(uri); // $ hasTaintFlow
40+
sink(selection); // $ hasTaintFlow
41+
sink(selectionArgs); // $ hasTaintFlow
42+
return 0;
43+
}
44+
45+
// "android.content;ContentProvider;true;delete;(Uri,Bundle);;Parameter[0..1];contentprovider",
46+
@Override
47+
public int delete(Uri uri, Bundle extras) {
48+
sink(uri); // $ hasTaintFlow
49+
sink(extras.get("some_key")); // $ hasTaintFlow
50+
return 0;
51+
}
52+
53+
// "android.content;ContentProvider;true;getType;(Uri);;Parameter[0];contentprovider",
54+
@Override
55+
public String getType(Uri uri) {
56+
sink(uri); // $ hasTaintFlow
57+
return null;
58+
}
59+
60+
// "android.content;ContentProvider;true;insert;(Uri,ContentValues,Bundle);;Parameter[0..2];contentprovider",
61+
@Override
62+
public Uri insert(Uri uri, ContentValues values, Bundle extras) {
63+
sink(uri); // $ hasTaintFlow
64+
sink(values); // $ hasTaintFlow
65+
sink(extras.get("some_key")); // $ hasTaintFlow
66+
return null;
67+
}
68+
69+
// "android.content;ContentProvider;true;insert;(Uri,ContentValues);;Parameter[0..1];contentprovider",
70+
@Override
71+
public Uri insert(Uri uri, ContentValues values) {
72+
sink(uri); // $ hasTaintFlow
73+
sink(values); // $ hasTaintFlow
74+
return null;
75+
}
76+
77+
// "android.content;ContentProvider;true;openAssetFile;(Uri,String,CancellationSignal);;Parameter[0];contentprovider",
78+
@Override
79+
public AssetFileDescriptor openAssetFile(Uri uri, String mode, CancellationSignal signal) {
80+
sink(uri); // $ hasTaintFlow
81+
sink(mode); // Safe
82+
sink(signal); // Safe
83+
return null;
84+
}
85+
86+
// "android.content;ContentProvider;true;openAssetFile;(Uri,String);;Parameter[0];contentprovider",
87+
@Override
88+
public AssetFileDescriptor openAssetFile(Uri uri, String mode) {
89+
sink(uri); // $ hasTaintFlow
90+
sink(mode); // Safe
91+
return null;
92+
}
93+
94+
// "android.content;ContentProvider;true;openTypedAssetFile;(Uri,String,Bundle,CancellationSignal);;Parameter[0..2];contentprovider",
95+
@Override
96+
public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts,
97+
CancellationSignal signal) throws RemoteException, FileNotFoundException {
98+
sink(uri); // $ hasTaintFlow
99+
sink(mimeTypeFilter); // $ hasTaintFlow
100+
sink(opts.get("some_key")); // $ hasTaintFlow
101+
sink(signal); // Safe
102+
return null;
103+
}
104+
105+
// "android.content;ContentProvider;true;openTypedAssetFile;(Uri,String,Bundle);;Parameter[0..2];contentprovider",
106+
@Override
107+
public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts)
108+
throws FileNotFoundException {
109+
sink(uri); // $ hasTaintFlow
110+
sink(mimeTypeFilter); // $ hasTaintFlow
111+
sink(opts.get("some_key")); // $ hasTaintFlow
112+
return null;
113+
}
114+
115+
// "android.content;ContentProvider;true;openFile;(Uri,String,CancellationSignal);;Parameter[0];contentprovider",
116+
@Override
117+
public ParcelFileDescriptor openFile(Uri uri, String mode, CancellationSignal signal) {
118+
sink(uri); // $ hasTaintFlow
119+
sink(mode); // Safe
120+
sink(signal); // Safe
121+
return null;
122+
}
123+
124+
// "android.content;ContentProvider;true;openFile;(Uri,String);;Parameter[0..1];contentprovider",
125+
@Override
126+
public ParcelFileDescriptor openFile(Uri uri, String mode) {
127+
sink(uri); // $ hasTaintFlow
128+
sink(mode); // Safe
129+
return null;
130+
}
131+
132+
// "android.content;ContentProvider;true;query;(Uri,String[],Bundle,CancellationSignal);;Parameter[0..2];contentprovider",
133+
@Override
134+
public Cursor query(Uri uri, String[] projection, Bundle queryArgs,
135+
CancellationSignal cancellationSignal) {
136+
sink(uri); // $ hasTaintFlow
137+
sink(projection); // $ hasTaintFlow
138+
sink(queryArgs.get("some_key")); // $ hasTaintFlow
139+
sink(cancellationSignal); // Safe
140+
return null;
141+
}
142+
143+
// "android.content;ContentProvider;true;query;(Uri,String[],String,String[],String);;Parameter[0..4];contentprovider",
144+
@Override
145+
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
146+
String sortOrder) {
147+
sink(uri); // $ hasTaintFlow
148+
sink(projection); // $ hasTaintFlow
149+
sink(selection); // $ hasTaintFlow
150+
sink(selectionArgs); // $ hasTaintFlow
151+
return null;
152+
}
153+
154+
// "android.content;ContentProvider;true;query;(Uri,String[],String,String[],String,CancellationSignal);;Parameter[0..4];contentprovider",
155+
@Override
156+
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
157+
String sortOrder, CancellationSignal cancellationSignal) {
158+
sink(uri); // $ hasTaintFlow
159+
sink(projection); // $ hasTaintFlow
160+
sink(selection); // $ hasTaintFlow
161+
sink(selectionArgs); // $ hasTaintFlow
162+
sink(sortOrder); // $ hasTaintFlow
163+
sink(cancellationSignal); // Safe
164+
return null;
165+
}
166+
167+
// "android.content;ContentProvider;true;update;(Uri,ContentValues,Bundle);;Parameter[0..2];contentprovider",
168+
@Override
169+
public int update(Uri uri, ContentValues values, Bundle extras) {
170+
sink(uri); // $ hasTaintFlow
171+
sink(values); // $ hasTaintFlow
172+
sink(extras.get("some_key")); // $ hasTaintFlow
173+
return 0;
174+
}
175+
176+
// "android.content;ContentProvider;true;update;(Uri,ContentValues,String,String[]);;Parameter[0..3];contentprovider"
177+
@Override
178+
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
179+
sink(uri); // $ hasTaintFlow
180+
sink(values); // $ hasTaintFlow
181+
sink(selection); // $ hasTaintFlow
182+
sink(selectionArgs); // $ hasTaintFlow
183+
return 0;
184+
}
185+
186+
@Override
187+
public boolean onCreate() {
188+
return false;
189+
}
190+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../../stubs/google-android-9.0.0

java/ql/test/library-tests/frameworks/android/content-provider/test.expected

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import java
2+
import semmle.code.java.dataflow.FlowSources
3+
import TestUtilities.InlineFlowTest
4+
5+
class ProviderTaintFlowConf extends DefaultTaintFlowConf {
6+
override predicate isSource(DataFlow::Node n) { n instanceof RemoteFlowSource }
7+
}
8+
9+
class ProviderInlineFlowTest extends InlineFlowTest {
10+
override DataFlow::Configuration getValueFlowConfig() { none() }
11+
12+
override DataFlow::Configuration getTaintFlowConfig() { result instanceof ProviderTaintFlowConf }
13+
}

0 commit comments

Comments
 (0)