Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ private string paramsStringPart(Callable c, int i) {
* Returns the empty string if the callable has no parameters.
* Parameter types are represented by their type erasure.
*/
cached
string paramsString(Callable c) { result = concat(int i | | paramsStringPart(c, i) order by i) }

private Element interpretElement0(
Expand Down
34 changes: 22 additions & 12 deletions java/ql/lib/semmle/code/java/frameworks/android/Android.qll
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ import java
import semmle.code.java.dataflow.ExternalFlow
import semmle.code.xml.AndroidManifest

/**
* Gets a transitive superType avoiding magic optimisation
*/
pragma[nomagic]
private RefType getASuperTypePlus(RefType t) { result = t.getASupertype+() }

/**
* Gets a reflexive/transitive superType avoiding magic optimisation
*/
pragma[inline]
private RefType getASuperTypeStar(RefType t) { result = getASuperTypePlus(t) or result = t }

/**
* An Android component. That is, either an activity, a service,
* a broadcast receiver, or a content provider.
*/
class AndroidComponent extends Class {
AndroidComponent() {
// The casts here are due to misoptimisation if they are missing
// but are not needed semantically.
this.(Class).getASupertype*().hasQualifiedName("android.app", "Activity") or
this.(Class).getASupertype*().hasQualifiedName("android.app", "Service") or
this.(Class).getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver") or
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentProvider") or
this.(Class).getASupertype*().hasQualifiedName("android.content", "ContentResolver")
getASuperTypeStar(this).hasQualifiedName("android.app", "Activity") or
getASuperTypeStar(this).hasQualifiedName("android.app", "Service") or
getASuperTypeStar(this).hasQualifiedName("android.content", "BroadcastReceiver") or
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentProvider") or
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentResolver")
}

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

/** An Android activity. */
class AndroidActivity extends ExportableAndroidComponent {
AndroidActivity() { this.getASupertype*().hasQualifiedName("android.app", "Activity") }
AndroidActivity() { getASuperTypeStar(this).hasQualifiedName("android.app", "Activity") }
}

/** An Android service. */
class AndroidService extends ExportableAndroidComponent {
AndroidService() { this.getASupertype*().hasQualifiedName("android.app", "Service") }
AndroidService() { getASuperTypeStar(this).hasQualifiedName("android.app", "Service") }
}

/** An Android broadcast receiver. */
class AndroidBroadcastReceiver extends ExportableAndroidComponent {
AndroidBroadcastReceiver() {
this.getASupertype*().hasQualifiedName("android.content", "BroadcastReceiver")
getASuperTypeStar(this).hasQualifiedName("android.content", "BroadcastReceiver")
}
}

/** An Android content provider. */
class AndroidContentProvider extends ExportableAndroidComponent {
AndroidContentProvider() {
this.getASupertype*().hasQualifiedName("android.content", "ContentProvider")
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentProvider")
}
}

/** An Android content resolver. */
class AndroidContentResolver extends AndroidComponent {
AndroidContentResolver() {
this.getASupertype*().hasQualifiedName("android.content", "ContentResolver")
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentResolver")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private predicate whitelist(string name) { name = "visit" }
* Method `m` has name `name`, number of parameters `numParams`
* and is declared in `t` or inherited from a supertype of `t`.
*/
pragma[nomagic]
private predicate candidateMethod(RefType t, Method m, string name, int numParam) {
exists(Method n | n.getSourceDeclaration() = m | t.inherits(n)) and
m.getName() = name and
Expand Down