Skip to content

Commit 447eb23

Browse files
committed
Java: Fix for tc magic issue with subtyping.
1 parent dea8dde commit 447eb23

File tree

1 file changed

+22
-12
lines changed
  • java/ql/lib/semmle/code/java/frameworks/android

1 file changed

+22
-12
lines changed

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,29 @@ import java
66
import semmle.code.java.dataflow.ExternalFlow
77
import semmle.code.xml.AndroidManifest
88

9+
/**
10+
* Gets a transitive superType avoiding magic optimisation
11+
*/
12+
pragma[nomagic]
13+
private RefType getASuperTypePlus(RefType t) { result = t.getASupertype+() }
14+
15+
/**
16+
* Gets a reflexive/transitive superType avoiding magic optimisation
17+
*/
18+
pragma[inline]
19+
private RefType getASuperTypeStar(RefType t) { result = getASuperTypePlus(t) or result = t }
20+
921
/**
1022
* An Android component. That is, either an activity, a service,
1123
* a broadcast receiver, or a content provider.
1224
*/
1325
class AndroidComponent extends Class {
1426
AndroidComponent() {
15-
// The casts here are due to misoptimisation if they are missing
16-
// but are not needed semantically.
17-
this.(Class).getASupertype*().hasQualifiedName("android.app", "Activity") or
18-
this.(Class).getASupertype*().hasQualifiedName("android.app", "Service") or
19-
this.(Class).getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver") or
20-
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentProvider") or
21-
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentResolver")
27+
getASuperTypeStar(this).hasQualifiedName("android.app", "Activity") or
28+
getASuperTypeStar(this).hasQualifiedName("android.app", "Service") or
29+
getASuperTypeStar(this).hasQualifiedName("android.content", "BroadcastReceiver") or
30+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentProvider") or
31+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentResolver")
2232
}
2333

2434
/** The XML element corresponding to this Android component. */
@@ -52,32 +62,32 @@ class ExportableAndroidComponent extends AndroidComponent {
5262

5363
/** An Android activity. */
5464
class AndroidActivity extends ExportableAndroidComponent {
55-
AndroidActivity() { this.getASupertype*().hasQualifiedName("android.app", "Activity") }
65+
AndroidActivity() { getASuperTypeStar(this).hasQualifiedName("android.app", "Activity") }
5666
}
5767

5868
/** An Android service. */
5969
class AndroidService extends ExportableAndroidComponent {
60-
AndroidService() { this.getASupertype*().hasQualifiedName("android.app", "Service") }
70+
AndroidService() { getASuperTypeStar(this).hasQualifiedName("android.app", "Service") }
6171
}
6272

6373
/** An Android broadcast receiver. */
6474
class AndroidBroadcastReceiver extends ExportableAndroidComponent {
6575
AndroidBroadcastReceiver() {
66-
this.getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver")
76+
getASuperTypeStar(this).hasQualifiedName("android.content", "BroadcastReceiver")
6777
}
6878
}
6979

7080
/** An Android content provider. */
7181
class AndroidContentProvider extends ExportableAndroidComponent {
7282
AndroidContentProvider() {
73-
this.getASupertype*().hasQualifiedName("android.content", "ContentProvider")
83+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentProvider")
7484
}
7585
}
7686

7787
/** An Android content resolver. */
7888
class AndroidContentResolver extends AndroidComponent {
7989
AndroidContentResolver() {
80-
this.getASupertype*().hasQualifiedName("android.content", "ContentResolver")
90+
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentResolver")
8191
}
8292
}
8393

0 commit comments

Comments
 (0)