Merge pull request #6755 from alexet/alexet/cache-params-string

Java: Fix more performance issues with future versions of codeql.
This commit is contained in:
Anders Schack-Mulligen
2021-10-01 12:54:53 +02:00
committed by GitHub
3 changed files with 24 additions and 12 deletions

View File

@@ -641,6 +641,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(

View File

@@ -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. */
@@ -52,25 +62,25 @@ 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")
}
/**
@@ -85,7 +95,7 @@ class AndroidContentProvider extends ExportableAndroidComponent {
/** An Android content resolver. */
class AndroidContentResolver extends AndroidComponent {
AndroidContentResolver() {
this.getASupertype*().hasQualifiedName("android.content", "ContentResolver")
getASuperTypeStar(this).hasQualifiedName("android.content", "ContentResolver")
}
}

View File

@@ -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