Skip to content

Commit f594411

Browse files
committed
C#: Re-factor isSupported for the telemetry queries.
1 parent 658cc33 commit f594411

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 8 additions & 1 deletion
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,14 @@ class ExternalApi extends DotNet::Callable {
104105
pragma[nomagic]
105106
predicate isSink() { sinkNode(this.getAnInput(), _) }
106107

108+
/** Holds if this API is a known neutral. */
109+
pragma[nomagic]
110+
predicate isNeutral() { this instanceof FlowSummaryImpl::Public::NeutralCallable }
111+
107112
/** 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() }
113+
predicate isSupported() {
114+
this.hasSummary() or this.isSource() or this.isSink() or this.isNeutral()
115+
}
109116
}
110117

111118
/**

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()

0 commit comments

Comments
 (0)