Skip to content

Commit f61b817

Browse files
authored
Merge pull request #11631 from jcogs33/jcogs33/update-externalapi-charpredicate
Java/C#: add `isUninteresting` to `ExternalApi` characteristic predicate
2 parents 0b849a3 + a889cc4 commit f61b817

15 files changed

+27
-66
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ class TestLibrary extends RefType {
2424
}
2525
}
2626

27+
/** Holds if the given callable is not worth supporting. */
28+
private predicate isUninteresting(DotNet::Callable c) {
29+
c.getDeclaringType() instanceof TestLibrary or
30+
c.(Constructor).isParameterless()
31+
}
32+
2733
/**
2834
* An external API from either the C# Standard Library or a 3rd party library.
2935
*/
3036
class ExternalApi extends DotNet::Callable {
3137
ExternalApi() {
3238
this.isUnboundDeclaration() and
3339
this.fromLibrary() and
34-
this.(Modifiable).isEffectivelyPublic()
40+
this.(Modifiable).isEffectivelyPublic() and
41+
not isUninteresting(this)
3542
}
3643

3744
/**
@@ -84,17 +91,6 @@ class ExternalApi extends DotNet::Callable {
8491
defaultAdditionalTaintStep(this.getAnInput(), _)
8592
}
8693

87-
/** Holds if this API is a constructor without parameters. */
88-
private predicate isParameterlessConstructor() {
89-
this instanceof Constructor and this.getNumberOfParameters() = 0
90-
}
91-
92-
/** Holds if this API is part of a common testing library or framework. */
93-
private predicate isTestLibrary() { this.getDeclaringType() instanceof TestLibrary }
94-
95-
/** Holds if this API is not worth supporting. */
96-
predicate isUninteresting() { this.isTestLibrary() or this.isParameterlessConstructor() }
97-
9894
/** Holds if this API is a known source. */
9995
predicate isSource() {
10096
this.getAnOutput() instanceof RemoteFlowSource or sourceNode(this.getAnOutput(), _)

csharp/ql/src/Telemetry/ExternalLibraryUsage.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ private predicate getRelevantUsages(string namespace, int usages) {
1414
usages =
1515
strictcount(Call c, ExternalApi api |
1616
c.getTarget().getUnboundDeclaration() = api and
17-
api.getNamespace() = namespace and
18-
not api.isUninteresting()
17+
api.getNamespace() = namespace
1918
)
2019
}
2120

csharp/ql/src/Telemetry/SupportedExternalApis.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSumma
1212
private import ExternalApi
1313

1414
private predicate relevant(ExternalApi api) {
15-
not api.isUninteresting() and
16-
(
17-
api.isSupported() or
18-
api instanceof FlowSummaryImpl::Public::NeutralCallable
19-
)
15+
api.isSupported() or
16+
api instanceof FlowSummaryImpl::Public::NeutralCallable
2017
}
2118

2219
from string info, int usages

csharp/ql/src/Telemetry/SupportedExternalSinks.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
1111
private import ExternalApi
1212

13-
private predicate relevant(ExternalApi api) {
14-
not api.isUninteresting() and
15-
api.isSink()
16-
}
13+
private predicate relevant(ExternalApi api) { api.isSink() }
1714

1815
from string info, int usages
1916
where Results<relevant/1>::restrict(info, usages)

csharp/ql/src/Telemetry/SupportedExternalSources.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
1111
private import ExternalApi
1212

13-
private predicate relevant(ExternalApi api) {
14-
not api.isUninteresting() and
15-
api.isSource()
16-
}
13+
private predicate relevant(ExternalApi api) { api.isSource() }
1714

1815
from string info, int usages
1916
where Results<relevant/1>::restrict(info, usages)

csharp/ql/src/Telemetry/SupportedExternalTaint.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
1111
private import ExternalApi
1212

13-
private predicate relevant(ExternalApi api) {
14-
not api.isUninteresting() and
15-
api.hasSummary()
16-
}
13+
private predicate relevant(ExternalApi api) { api.hasSummary() }
1714

1815
from string info, int usages
1916
where Results<relevant/1>::restrict(info, usages)

csharp/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSumma
1212
private import ExternalApi
1313

1414
private predicate relevant(ExternalApi api) {
15-
not api.isUninteresting() and
1615
not api.isSupported() and
1716
not api instanceof FlowSummaryImpl::Public::NeutralCallable
1817
}

csharp/ql/src/meta/frameworks/UnsupportedExternalAPIs.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ private import Telemetry.ExternalApi
1616
from Call c, ExternalApi api
1717
where
1818
c.getTarget().getUnboundDeclaration() = api and
19-
not api.isUninteresting() and
2019
not api.isSupported() and
2120
not api instanceof FlowSummaryImpl::Public::NeutralCallable
2221
select c, "Call to unsupported external API $@.", api, api.toString()

java/ql/src/Telemetry/ExternalApi.qll

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ private string containerAsJar(Container container) {
3131
if container instanceof JarFile then result = container.getBaseName() else result = "rt.jar"
3232
}
3333

34+
/** Holds if the given callable is not worth supporting. */
35+
private predicate isUninteresting(Callable c) {
36+
c.getDeclaringType() instanceof TestLibrary or
37+
c.(Constructor).isParameterless()
38+
}
39+
3440
/**
3541
* An external API from either the Standard Library or a 3rd party library.
3642
*/
3743
class ExternalApi extends Callable {
38-
ExternalApi() { not this.fromSource() }
44+
ExternalApi() { not this.fromSource() and not isUninteresting(this) }
3945

4046
/**
4147
* Gets information about the external API in the form expected by the CSV modeling framework.
@@ -73,18 +79,6 @@ class ExternalApi extends Callable {
7379
TaintTracking::localAdditionalTaintStep(this.getAnInput(), _)
7480
}
7581

76-
/** Holds if this API is a constructor without parameters. */
77-
private predicate isParameterlessConstructor() {
78-
this instanceof Constructor and this.getNumberOfParameters() = 0
79-
}
80-
81-
/** Holds if this API is part of a common testing library or framework. */
82-
private predicate isTestLibrary() { this.getDeclaringType() instanceof TestLibrary }
83-
84-
/** Holds if this API is not worth supporting. */
85-
predicate isUninteresting() { this.isTestLibrary() or this.isParameterlessConstructor() }
86-
87-
/** Holds if this API is a known source. */
8882
predicate isSource() {
8983
this.getAnOutput() instanceof RemoteFlowSource or sourceNode(this.getAnOutput(), _)
9084
}

java/ql/src/Telemetry/ExternalLibraryUsage.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ private predicate getRelevantUsages(string jarname, int usages) {
1414
strictcount(Call c, ExternalApi a |
1515
c.getCallee().getSourceDeclaration() = a and
1616
not c.getFile() instanceof GeneratedFile and
17-
a.jarContainer() = jarname and
18-
not a.isUninteresting()
17+
a.jarContainer() = jarname
1918
)
2019
}
2120

0 commit comments

Comments
 (0)