Skip to content

Commit cf659f9

Browse files
authored
Merge pull request github#12261 from michaelnebel/csharpjava/refactorissupported
C#/Java: Re-factor the `isSupported` predicate.
2 parents ca94e02 + 47c69d9 commit cf659f9

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import semmle.code.csharp.dataflow.FlowSummary
88
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
99
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
1010
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
11+
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1112
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
1213
private import semmle.code.csharp.security.dataflow.flowsources.Remote
1314

@@ -104,8 +105,17 @@ class ExternalApi extends DotNet::Callable {
104105
pragma[nomagic]
105106
predicate isSink() { sinkNode(this.getAnInput(), _) }
106107

107-
/** Holds if this API is supported by existing CodeQL libraries, that is, it is either a recognized source or sink or has a flow summary. */
108-
predicate isSupported() { this.hasSummary() or this.isSource() or this.isSink() }
108+
/** Holds if this API is a known neutral. */
109+
pragma[nomagic]
110+
predicate isNeutral() { this instanceof FlowSummaryImpl::Public::NeutralCallable }
111+
112+
/**
113+
* Holds if this API is supported by existing CodeQL libraries, that is, it is either a
114+
* recognized source, sink or neutral or it has a flow summary.
115+
*/
116+
predicate isSupported() {
117+
this.hasSummary() or this.isSource() or this.isSink() or this.isNeutral()
118+
}
109119
}
110120

111121
/**

csharp/ql/src/Telemetry/SupportedExternalApis.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88

99
private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
11-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1211
private import ExternalApi
1312

14-
private predicate relevant(ExternalApi api) {
15-
api.isSupported() or
16-
api instanceof FlowSummaryImpl::Public::NeutralCallable
17-
}
13+
private predicate relevant(ExternalApi api) { api.isSupported() }
1814

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

csharp/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,9 @@
77
*/
88

99
private import csharp
10-
private import semmle.code.csharp.dispatch.Dispatch
11-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1210
private import ExternalApi
1311

14-
private predicate relevant(ExternalApi api) {
15-
not api.isSupported() and
16-
not api instanceof FlowSummaryImpl::Public::NeutralCallable
17-
}
12+
private predicate relevant(ExternalApi api) { not api.isSupported() }
1813

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

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
*/
1010

1111
private import csharp
12-
private import semmle.code.csharp.dispatch.Dispatch
13-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1412
private import Telemetry.ExternalApi
1513

1614
from Call c, ExternalApi api
1715
where
1816
c.getTarget().getUnboundDeclaration() = api and
19-
not api.isSupported() and
20-
not api instanceof FlowSummaryImpl::Public::NeutralCallable
17+
not api.isSupported()
2118
select c, "Call to unsupported external API $@.", api, api.toString()

java/ql/src/Telemetry/ExternalApi.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import semmle.code.java.dataflow.ExternalFlow
66
private import semmle.code.java.dataflow.FlowSources
77
private import semmle.code.java.dataflow.FlowSummary
88
private import semmle.code.java.dataflow.internal.DataFlowPrivate
9+
private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
910
private import semmle.code.java.dataflow.TaintTracking
1011

1112
pragma[nomagic]
@@ -91,8 +92,17 @@ class ExternalApi extends Callable {
9192
pragma[nomagic]
9293
predicate isSink() { sinkNode(this.getAnInput(), _) }
9394

94-
/** Holds if this API is supported by existing CodeQL libraries, that is, it is either a recognized source or sink or has a flow summary. */
95-
predicate isSupported() { this.hasSummary() or this.isSource() or this.isSink() }
95+
/** Holds if this API is a known neutral. */
96+
pragma[nomagic]
97+
predicate isNeutral() { this = any(FlowSummaryImpl::Public::NeutralCallable nsc).asCallable() }
98+
99+
/**
100+
* Holds if this API is supported by existing CodeQL libraries, that is, it is either a
101+
* recognized source, sink or neutral or it has a flow summary.
102+
*/
103+
predicate isSupported() {
104+
this.hasSummary() or this.isSource() or this.isSink() or this.isNeutral()
105+
}
96106
}
97107

98108
/** DEPRECATED: Alias for ExternalApi */

java/ql/src/Telemetry/SupportedExternalApis.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
*/
88

99
import java
10-
import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1110
import ExternalApi
1211

13-
private predicate relevant(ExternalApi api) {
14-
api.isSupported() or
15-
api = any(FlowSummaryImpl::Public::NeutralCallable nsc).asCallable()
16-
}
12+
private predicate relevant(ExternalApi api) { api.isSupported() }
1713

1814
from string apiName, int usages
1915
where Results<relevant/1>::restrict(apiName, usages)

java/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@
77
*/
88

99
import java
10-
import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1110
import ExternalApi
1211

13-
private predicate relevant(ExternalApi api) {
14-
not api.isSupported() and
15-
not api = any(FlowSummaryImpl::Public::NeutralCallable nsc).asCallable()
16-
}
12+
private predicate relevant(ExternalApi api) { not api.isSupported() }
1713

1814
from string apiName, int usages
1915
where Results<relevant/1>::restrict(apiName, usages)

0 commit comments

Comments
 (0)