Skip to content

Commit 8791a20

Browse files
authored
Merge branch 'main' into sabrowning1/clarify-codeql-installation-vscode
2 parents af12eed + 2836c5e commit 8791a20

10 files changed

+89
-90
lines changed

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ private import semmle.code.csharp.security.dataflow.flowsources.Remote
1717
class TestLibrary extends RefType {
1818
TestLibrary() {
1919
this.getNamespace()
20-
.getName()
21-
.matches(["NUnit.Framework%", "Xunit%", "Microsoft.VisualStudio.TestTools.UnitTesting%"])
20+
.getQualifiedName()
21+
.matches([
22+
"NUnit.Framework%", "Xunit%", "Microsoft.VisualStudio.TestTools.UnitTesting%", "Moq%"
23+
])
2224
}
2325
}
2426

@@ -114,29 +116,39 @@ class ExternalApi extends DotNet::Callable {
114116
int resultLimit() { result = 1000 }
115117

116118
/**
117-
* Holds if the relevant usage count of `api` is `usages`.
119+
* Holds if it is relevant to count usages of `api`.
118120
*/
119-
signature predicate relevantUsagesSig(ExternalApi api, int usages);
121+
signature predicate relevantApi(ExternalApi api);
120122

121123
/**
122124
* Given a predicate to count relevant API usages, this module provides a predicate
123125
* for restricting the number or returned results based on a certain limit.
124126
*/
125-
module Results<relevantUsagesSig/2 getRelevantUsages> {
126-
private int getOrder(ExternalApi api) {
127-
api =
128-
rank[result](ExternalApi a, int usages |
129-
getRelevantUsages(a, usages)
127+
module Results<relevantApi/1 getRelevantUsages> {
128+
private int getUsages(string apiInfo) {
129+
result =
130+
strictcount(DispatchCall c, ExternalApi api |
131+
c = api.getACall() and
132+
apiInfo = api.getInfo() and
133+
getRelevantUsages(api)
134+
)
135+
}
136+
137+
private int getOrder(string apiInfo) {
138+
apiInfo =
139+
rank[result](string info, int usages |
140+
usages = getUsages(info)
130141
|
131-
a order by usages desc, a.getInfo()
142+
info order by usages desc, info
132143
)
133144
}
134145

135146
/**
136-
* Holds if `api` is being used `usages` times and if it is
137-
* in the top results (guarded by resultLimit).
147+
* Holds if there exists an API with `apiInfo` that is being used `usages` times
148+
* and if it is in the top results (guarded by resultLimit).
138149
*/
139-
predicate restrict(ExternalApi api, int usages) {
140-
getRelevantUsages(api, usages) and getOrder(api) <= resultLimit()
150+
predicate restrict(string apiInfo, int usages) {
151+
usages = getUsages(apiInfo) and
152+
getOrder(apiInfo) <= resultLimit()
141153
}
142154
}

csharp/ql/src/Telemetry/SupportedExternalSinks.ql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
1111
private import ExternalApi
1212

13-
private predicate getRelevantUsages(ExternalApi api, int usages) {
13+
private predicate relevant(ExternalApi api) {
1414
not api.isUninteresting() and
15-
api.isSink() and
16-
usages = strictcount(DispatchCall c | c = api.getACall())
15+
api.isSink()
1716
}
1817

19-
from ExternalApi api, int usages
20-
where Results<getRelevantUsages/2>::restrict(api, usages)
21-
select api.getInfo() as info, usages order by usages desc
18+
from string info, int usages
19+
where Results<relevant/1>::restrict(info, usages)
20+
select info, usages order by usages desc

csharp/ql/src/Telemetry/SupportedExternalSources.ql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
1111
private import ExternalApi
1212

13-
private predicate getRelevantUsages(ExternalApi api, int usages) {
13+
private predicate relevant(ExternalApi api) {
1414
not api.isUninteresting() and
15-
api.isSource() and
16-
usages = strictcount(DispatchCall c | c = api.getACall())
15+
api.isSource()
1716
}
1817

19-
from ExternalApi api, int usages
20-
where Results<getRelevantUsages/2>::restrict(api, usages)
21-
select api.getInfo() as info, usages order by usages desc
18+
from string info, int usages
19+
where Results<relevant/1>::restrict(info, usages)
20+
select info, usages order by usages desc

csharp/ql/src/Telemetry/SupportedExternalTaint.ql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
1111
private import ExternalApi
1212

13-
private predicate getRelevantUsages(ExternalApi api, int usages) {
13+
private predicate relevant(ExternalApi api) {
1414
not api.isUninteresting() and
15-
api.hasSummary() and
16-
usages = strictcount(DispatchCall c | c = api.getACall())
15+
api.hasSummary()
1716
}
1817

19-
from ExternalApi api, int usages
20-
where Results<getRelevantUsages/2>::restrict(api, usages)
21-
select api.getInfo() as info, usages order by usages desc
18+
from string info, int usages
19+
where Results<relevant/1>::restrict(info, usages)
20+
select info, usages order by usages desc

csharp/ql/src/Telemetry/UnsupportedExternalAPIs.ql

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

15-
private predicate getRelevantUsages(ExternalApi api, int usages) {
15+
private predicate relevant(ExternalApi api) {
1616
not api.isUninteresting() and
1717
not api.isSupported() and
18-
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable and
19-
usages = strictcount(DispatchCall c | c = api.getACall())
18+
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
2019
}
2120

22-
from ExternalApi api, int usages
23-
where Results<getRelevantUsages/2>::restrict(api, usages)
24-
select api.getInfo() as info, usages order by usages desc
21+
from string info, int usages
22+
where Results<relevant/1>::restrict(info, usages)
23+
select info, usages order by usages desc

java/ql/src/Telemetry/ExternalApi.qll

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,40 @@ deprecated class ExternalAPI = ExternalApi;
105105
int resultLimit() { result = 1000 }
106106

107107
/**
108-
* Holds if the relevant usage count of `api` is `usages`.
108+
* Holds if it is relevant to count usages of `api`.
109109
*/
110-
signature predicate relevantUsagesSig(ExternalApi api, int usages);
110+
signature predicate relevantApi(ExternalApi api);
111111

112112
/**
113113
* Given a predicate to count relevant API usages, this module provides a predicate
114114
* for restricting the number or returned results based on a certain limit.
115115
*/
116-
module Results<relevantUsagesSig/2 getRelevantUsages> {
117-
private int getOrder(ExternalApi api) {
118-
api =
119-
rank[result](ExternalApi a, int usages |
120-
getRelevantUsages(a, usages)
116+
module Results<relevantApi/1 getRelevantUsages> {
117+
private int getUsages(string apiName) {
118+
result =
119+
strictcount(Call c, ExternalApi api |
120+
c.getCallee().getSourceDeclaration() = api and
121+
not c.getFile() instanceof GeneratedFile and
122+
apiName = api.getApiName() and
123+
getRelevantUsages(api)
124+
)
125+
}
126+
127+
private int getOrder(string apiInfo) {
128+
apiInfo =
129+
rank[result](string info, int usages |
130+
usages = getUsages(info)
121131
|
122-
a order by usages desc, a.getApiName()
132+
info order by usages desc, info
123133
)
124134
}
125135

126136
/**
127-
* Holds if `api` is being used `usages` times and if it is
128-
* in the top results (guarded by resultLimit).
137+
* Holds if there exists an API with `apiName` that is being used `usages` times
138+
* and if it is in the top results (guarded by resultLimit).
129139
*/
130-
predicate restrict(ExternalApi api, int usages) {
131-
getRelevantUsages(api, usages) and getOrder(api) <= resultLimit()
140+
predicate restrict(string apiName, int usages) {
141+
usages = getUsages(apiName) and
142+
getOrder(apiName) <= resultLimit()
132143
}
133144
}

java/ql/src/Telemetry/SupportedExternalSinks.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
import java
1010
import ExternalApi
1111

12-
private predicate getRelevantUsages(ExternalApi api, int usages) {
12+
private predicate relevant(ExternalApi api) {
1313
not api.isUninteresting() and
14-
api.isSink() and
15-
usages =
16-
strictcount(Call c |
17-
c.getCallee().getSourceDeclaration() = api and
18-
not c.getFile() instanceof GeneratedFile
19-
)
14+
api.isSink()
2015
}
2116

22-
from ExternalApi api, int usages
23-
where Results<getRelevantUsages/2>::restrict(api, usages)
24-
select api.getApiName() as apiname, usages order by usages desc
17+
from string apiName, int usages
18+
where Results<relevant/1>::restrict(apiName, usages)
19+
select apiName, usages order by usages desc

java/ql/src/Telemetry/SupportedExternalSources.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
import java
1010
import ExternalApi
1111

12-
private predicate getRelevantUsages(ExternalApi api, int usages) {
12+
private predicate relevant(ExternalApi api) {
1313
not api.isUninteresting() and
14-
api.isSource() and
15-
usages =
16-
strictcount(Call c |
17-
c.getCallee().getSourceDeclaration() = api and
18-
not c.getFile() instanceof GeneratedFile
19-
)
14+
api.isSource()
2015
}
2116

22-
from ExternalApi api, int usages
23-
where Results<getRelevantUsages/2>::restrict(api, usages)
24-
select api.getApiName() as apiname, usages order by usages desc
17+
from string apiName, int usages
18+
where Results<relevant/1>::restrict(apiName, usages)
19+
select apiName, usages order by usages desc

java/ql/src/Telemetry/SupportedExternalTaint.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
import java
1010
import ExternalApi
1111

12-
private predicate getRelevantUsages(ExternalApi api, int usages) {
12+
private predicate relevant(ExternalApi api) {
1313
not api.isUninteresting() and
14-
api.hasSummary() and
15-
usages =
16-
strictcount(Call c |
17-
c.getCallee().getSourceDeclaration() = api and
18-
not c.getFile() instanceof GeneratedFile
19-
)
14+
api.hasSummary()
2015
}
2116

22-
from ExternalApi api, int usages
23-
where Results<getRelevantUsages/2>::restrict(api, usages)
24-
select api.getApiName() as apiname, usages order by usages desc
17+
from string apiName, int usages
18+
where Results<relevant/1>::restrict(apiName, usages)
19+
select apiName, usages order by usages desc

java/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1111
import semmle.code.java.dataflow.internal.NegativeSummary
1212
import ExternalApi
1313

14-
private predicate getRelevantUsages(ExternalApi api, int usages) {
14+
private predicate relevant(ExternalApi api) {
1515
not api.isUninteresting() and
1616
not api.isSupported() and
17-
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable and
18-
usages =
19-
strictcount(Call c |
20-
c.getCallee().getSourceDeclaration() = api and
21-
not c.getFile() instanceof GeneratedFile
22-
)
17+
not api instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
2318
}
2419

25-
from ExternalApi api, int usages
26-
where Results<getRelevantUsages/2>::restrict(api, usages)
27-
select api.getApiName() as apiname, usages order by usages desc
20+
from string apiName, int usages
21+
where Results<relevant/1>::restrict(apiName, usages)
22+
select apiName, usages order by usages desc

0 commit comments

Comments
 (0)