Skip to content

Commit 13dd9a6

Browse files
committed
C#: Address review comments.
1 parent 50a9219 commit 13dd9a6

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/** Provides classes and predicates related to handling APIs from external libraries. */
22

33
private import csharp
4-
private import dotnet
54
private import semmle.code.csharp.dispatch.Dispatch
65
private import semmle.code.csharp.dataflow.ExternalFlow
76
private import semmle.code.csharp.dataflow.FlowSummary
@@ -14,15 +13,15 @@ private import semmle.code.csharp.security.dataflow.flowsources.Remote
1413
private import TestLibrary
1514

1615
/** Holds if the given callable is not worth supporting. */
17-
private predicate isUninteresting(DotNet::Callable c) {
16+
private predicate isUninteresting(Callable c) {
1817
c.getDeclaringType() instanceof TestLibrary or
1918
c.(Constructor).isParameterless()
2019
}
2120

2221
/**
2322
* An external API from either the C# Standard Library or a 3rd party library.
2423
*/
25-
class ExternalApi extends DotNet::Callable {
24+
class ExternalApi extends Callable {
2625
ExternalApi() {
2726
this.isUnboundDeclaration() and
2827
this.fromLibrary() and

csharp/ql/src/utils/modeleditor/ApplicationModeEndpointsQuery.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
private import csharp
22
private import semmle.code.csharp.dataflow.ExternalFlow
3-
private import semmle.code.csharp.dataflow.FlowSummary
43
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
54
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
65
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
76
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
87
private import semmle.code.csharp.security.dataflow.flowsources.Remote
98
private import ModelEditor
109

10+
/**
11+
* A class of effectively public callables in library code.
12+
*/
1113
class ExternalEndpoint extends Endpoint {
1214
ExternalEndpoint() { this.fromLibrary() }
1315

@@ -22,18 +24,16 @@ class ExternalEndpoint extends Endpoint {
2224

2325
/** Gets a node that is an output from a call to this API. */
2426
private DataFlow::Node getAnOutput() {
25-
exists(
26-
Call c, DataFlowDispatch::NonDelegateDataFlowCall dc, DataFlowImplCommon::ReturnKindExt ret
27-
|
27+
exists(Call c, DataFlowDispatch::NonDelegateDataFlowCall dc |
2828
dc.getDispatchCall().getCall() = c and
2929
c.getTarget().getUnboundDeclaration() = this
3030
|
31-
result = ret.getAnOutNode(dc)
31+
result = DataFlowDispatch::getAnOutNode(dc, _)
3232
)
3333
}
3434

3535
override predicate hasSummary() {
36-
this instanceof SummarizedCallable
36+
Endpoint.super.hasSummary()
3737
or
3838
defaultAdditionalTaintStep(this.getAnInput(), _)
3939
}

csharp/ql/src/utils/modeleditor/FrameworkModeEndpointsQuery.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
private import csharp
22
private import semmle.code.csharp.dataflow.ExternalFlow
3-
private import semmle.code.csharp.dataflow.FlowSummary
43
private import semmle.code.csharp.frameworks.Test
54
private import ModelEditor
65

6+
/**
7+
* A class of effectively public callables from source code.
8+
*/
79
class PublicEndpointFromSource extends Endpoint {
810
PublicEndpointFromSource() { this.fromSource() and not this.getFile() instanceof TestFile }
911

10-
override predicate hasSummary() { this instanceof SummarizedCallable }
11-
1212
override predicate isSource() { this instanceof SourceCallable }
1313

1414
override predicate isSink() { this instanceof SinkCallable }

csharp/ql/src/utils/modeleditor/ModelEditor.qll

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/** Provides classes and predicates related to handling APIs for the VS Code extension. */
22

33
private import csharp
4-
private import dotnet
4+
private import semmle.code.csharp.dataflow.FlowSummary
55
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
66
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
77
private import semmle.code.csharp.frameworks.Test
88
private import Telemetry.TestLibrary
99

1010
/** Holds if the given callable is not worth supporting. */
11-
private predicate isUninteresting(DotNet::Callable c) {
11+
private predicate isUninteresting(Callable c) {
1212
c.getDeclaringType() instanceof TestLibrary or
1313
c.(Constructor).isParameterless() or
1414
c.getDeclaringType() instanceof AnonymousClass
@@ -17,7 +17,7 @@ private predicate isUninteresting(DotNet::Callable c) {
1717
/**
1818
* A callable method or accessor from either the C# Standard Library, a 3rd party library, or from the source.
1919
*/
20-
class Endpoint extends DotNet::Callable {
20+
class Endpoint extends Callable {
2121
Endpoint() {
2222
[this.(Modifiable), this.(Accessor).getDeclaration()].isEffectivelyPublic() and
2323
not isUninteresting(this) and
@@ -64,7 +64,7 @@ class Endpoint extends DotNet::Callable {
6464

6565
/** Holds if this API has a supported summary. */
6666
pragma[nomagic]
67-
abstract predicate hasSummary();
67+
predicate hasSummary() { this instanceof SummarizedCallable }
6868

6969
/** Holds if this API is a known source. */
7070
pragma[nomagic]
@@ -88,10 +88,7 @@ class Endpoint extends DotNet::Callable {
8888
}
8989

9090
boolean isSupported(Endpoint endpoint) {
91-
endpoint.isSupported() and result = true
92-
or
93-
not endpoint.isSupported() and
94-
result = false
91+
if endpoint.isSupported() then result = true else result = false
9592
}
9693

9794
string supportedType(Endpoint endpoint) {
@@ -114,16 +111,15 @@ string methodClassification(Call method) {
114111
}
115112

116113
/**
117-
* Gets the nested name of the declaration.
114+
* Gets the nested name of the type `t`.
118115
*
119-
* If the declaration is not a nested type, the result is the same as `getName()`.
116+
* If the type is not a nested type, the result is the same as `getName()`.
120117
* Otherwise the name of the nested type is prefixed with a `+` and appended to
121118
* the name of the enclosing type, which might be a nested type as well.
122119
*/
123-
private string nestedName(Declaration declaration) {
124-
not exists(declaration.getDeclaringType().getUnboundDeclaration()) and
125-
result = declaration.getName()
120+
private string nestedName(Type t) {
121+
not exists(t.getDeclaringType().getUnboundDeclaration()) and
122+
result = t.getName()
126123
or
127-
nestedName(declaration.getDeclaringType().getUnboundDeclaration()) + "+" + declaration.getName() =
128-
result
124+
nestedName(t.getDeclaringType().getUnboundDeclaration()) + "+" + t.getName() = result
129125
}

0 commit comments

Comments
 (0)