Skip to content

Commit 6be41b0

Browse files
committed
C#/Java: Address review comments.
1 parent b0a24a7 commit 6be41b0

File tree

7 files changed

+40
-33
lines changed

7 files changed

+40
-33
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,26 @@ class ExternalApi extends DataFlowDispatch::DataFlowCallable {
5858
*/
5959
string getInfo() { result = this.getInfoPrefix() + "#" + this.getSignature() }
6060

61-
/** Gets a node that is an input to a call to this API. */
62-
private ArgumentNode getAnInput() {
63-
exists(DispatchCall call |
64-
result.getCall().(DataFlowDispatch::NonDelegateDataFlowCall).getDispatchCall() = call
65-
|
66-
this = call.getADynamicTarget().getUnboundDeclaration()
61+
/** Gets a call to this API callable. */
62+
DispatchCall getACall() {
63+
exists(DataFlowDispatch::NonDelegateDataFlowCall call | call.getDispatchCall() = result |
64+
this = result.getADynamicTarget().getUnboundDeclaration()
6765
or
68-
this = call.getAStaticTarget().getUnboundDeclaration()
66+
this = result.getAStaticTarget().getUnboundDeclaration()
6967
)
7068
}
7169

70+
/** Gets a node that is an input to a call to this API. */
71+
private ArgumentNode getAnInput() {
72+
result.getCall().(DataFlowDispatch::NonDelegateDataFlowCall).getDispatchCall() = this.getACall()
73+
}
74+
7275
/** Gets a node that is an output from a call to this API. */
7376
private DataFlow::Node getAnOutput() {
7477
exists(DataFlowDispatch::NonDelegateDataFlowCall call, DataFlowImplCommon::ReturnKindExt ret |
7578
result = ret.getAnOutNode(call)
7679
|
77-
this = call.getDispatchCall().getADynamicTarget().getUnboundDeclaration()
78-
or
79-
this = call.getDispatchCall().getAStaticTarget().getUnboundDeclaration()
80+
this.getACall() = call.getDispatchCall()
8081
)
8182
}
8283

csharp/ql/src/Telemetry/ExternalLibraryUsage.ql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
* @id csharp/telemetry/external-libs
77
*/
88

9-
import csharp
10-
import ExternalApi
9+
private import csharp
10+
private import semmle.code.csharp.dispatch.Dispatch
11+
private import ExternalApi
1112

1213
from int usages, string info
1314
where
1415
usages =
15-
strictcount(Call c, ExternalApi api |
16-
c.getTarget().getUnboundDeclaration() = api and
16+
strictcount(DispatchCall c, ExternalApi api |
17+
c = api.getACall() and
1718
api.getInfoPrefix() = info and
1819
not api.isUninteresting()
1920
)

csharp/ql/src/Telemetry/SupportedExternalSinks.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
* @id csharp/telemetry/supported-external-api-sinks
77
*/
88

9-
import csharp
10-
import ExternalApi
9+
private import csharp
10+
private import semmle.code.csharp.dispatch.Dispatch
11+
private import ExternalApi
1112

1213
from ExternalApi api, int usages
1314
where
1415
not api.isUninteresting() and
1516
api.isSink() and
16-
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
17+
usages = strictcount(DispatchCall c | c = api.getACall())
1718
select api.getInfo() as info, usages order by usages desc

csharp/ql/src/Telemetry/SupportedExternalSources.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
* @id csharp/telemetry/supported-external-api-sources
77
*/
88

9-
import csharp
10-
import ExternalApi
9+
private import csharp
10+
private import semmle.code.csharp.dispatch.Dispatch
11+
private import ExternalApi
1112

1213
from ExternalApi api, int usages
1314
where
1415
not api.isUninteresting() and
1516
api.isSource() and
16-
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
17+
usages = strictcount(DispatchCall c | c = api.getACall())
1718
select api.getInfo() as info, usages order by usages desc

csharp/ql/src/Telemetry/SupportedExternalTaint.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
* @id csharp/telemetry/supported-external-api-taint
77
*/
88

9-
import csharp
10-
import ExternalApi
9+
private import csharp
10+
private import semmle.code.csharp.dispatch.Dispatch
11+
private import ExternalApi
1112

1213
from ExternalApi api, int usages
1314
where
1415
not api.isUninteresting() and
1516
api.hasSummary() and
16-
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
17+
usages = strictcount(DispatchCall c | c = api.getACall())
1718
select api.getInfo() as info, usages order by usages desc

csharp/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
* @id csharp/telemetry/unsupported-external-api
77
*/
88

9-
import csharp
10-
import ExternalApi
9+
private import csharp
10+
private import semmle.code.csharp.dispatch.Dispatch
11+
private import ExternalApi
1112

1213
from ExternalApi api, int usages
1314
where
1415
not api.isUninteresting() and
1516
not api.isSupported() and
16-
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
17+
usages = strictcount(DispatchCall c | c = api.getACall())
1718
select api.getInfo() as info, usages order by usages desc

java/ql/src/Telemetry/ExternalApi.qll

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ private class TestLibrary extends RefType {
2727
}
2828
}
2929

30+
private string containerAsJar(Container container) {
31+
if container instanceof JarFile then result = container.getBaseName() else result = "rt.jar"
32+
}
33+
3034
/**
3135
* An external API from either the Standard Library or a 3rd party library.
3236
*/
@@ -42,16 +46,10 @@ class ExternalApi extends Callable {
4246
"#" + this.getName() + paramsString(this)
4347
}
4448

45-
private string containerAsJar(Container container) {
46-
if container instanceof JarFile then result = container.getBaseName() else result = "rt.jar"
47-
}
48-
4949
/**
5050
* Gets the jar file containing this API. Normalizes the Java Runtime to "rt.jar" despite the presence of modules.
5151
*/
52-
string jarContainer() {
53-
result = this.containerAsJar(this.getCompilationUnit().getParentContainer*())
54-
}
52+
string jarContainer() { result = containerAsJar(this.getCompilationUnit().getParentContainer*()) }
5553

5654
/** Gets a node that is an input to a call to this API. */
5755
private DataFlow::Node getAnInput() {
@@ -97,3 +95,6 @@ class ExternalApi extends Callable {
9795
/** 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. */
9896
predicate isSupported() { this.hasSummary() or this.isSource() or this.isSink() }
9997
}
98+
99+
/** DEPRECATED: Alias for ExternalApi */
100+
deprecated class ExternalAPI = ExternalApi;

0 commit comments

Comments
 (0)