Skip to content

Commit 8e2e8cc

Browse files
Add qhelp
1 parent 4aed1a1 commit 8e2e8cc

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
...
2+
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
3+
BroadcastReceiver sReceiver = new ShutDownReceiver();
4+
context.registerReceiver(sReceiver, filter);
5+
...
6+
7+
public class ShutdownReceiver extends BroadcastReceiver {
8+
@Override
9+
public void onReceive(final Context context, final Intent intent) {
10+
mainActivity.saveLocalData();
11+
mainActivity.stopActivity();
12+
}
13+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
...
2+
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
3+
BroadcastReceiver sReceiver = new ShutDownReceiver();
4+
context.registerReceiver(sReceiver, filter);
5+
...
6+
7+
public class ShutdownReceiver extends BroadcastReceiver {
8+
@Override
9+
public void onReceive(final Context context, final Intent intent) {
10+
if (!intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
11+
return;
12+
}
13+
mainActivity.saveLocalData();
14+
mainActivity.stopActivity();
15+
}
16+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
5+
<qhelp>
6+
7+
<overview>
8+
<p>
9+
When an android application uses a <code>BroadcastReciever</code> to receive Intents,
10+
it is also able to receive explicit Intents that are sent drctly to it, egardless of its filter.
11+
12+
Certain intent actions are only able to be sent by the operating system, not third-party applications.
13+
However, a <code>BroadcastReceiver</code> that is registered to recieve system intents is still able to recieve
14+
other intents from a third-party application, so it should check that the intent received has the expected action.
15+
Otherwise, a third-party application could impersonate the system this way and cause unintended behaviour, such as a denial of service.
16+
</p>
17+
</overview>
18+
19+
<example>
20+
<p>In the following code, the <code>ShutdownReceiver</code> initiates a shutdown procedure upon receiving an Intent,
21+
without checking that the received action is indeed <code>ACTION_SHUTDOWN</code>. This allows third-party applications to
22+
send explicit intents to this receiver to cause a denial of service.</p>
23+
<sample src="Bad.java" />
24+
</example>
25+
26+
<recommendation>
27+
<p>
28+
In the <code>onReceive</code> method of a <code>BroadcastReciever</code>, the action of the received Intent should be checked. The following code demonstrates this.
29+
</p>
30+
<sample src="Good.java" />
31+
</recommendation>
32+
33+
34+
35+
<references>
36+
37+
</references>
38+
39+
</qhelp>

0 commit comments

Comments
 (0)