Skip to content

Commit bfb206c

Browse files
committed
C#: Let ExternalApi extend DataFlowCallable instead of Callable.
1 parent e1d4c1b commit bfb206c

File tree

10 files changed

+27
-25
lines changed

10 files changed

+27
-25
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,19 +2038,20 @@ abstract class SyntheticField extends string {
20382038
*/
20392039
predicate containerContent(DataFlow::Content c) { c instanceof DataFlow::ElementContent }
20402040

2041+
/** Gets the string representation of the parameters of `c`. */
2042+
string parameterQualifiedTypeNamesToString(DataFlowCallable c) {
2043+
result =
2044+
concat(Parameter p, int i |
2045+
p = c.getParameter(i)
2046+
|
2047+
p.getType().getQualifiedName(), "," order by i
2048+
)
2049+
}
2050+
20412051
/**
20422052
* A module containing predicates related to generating models as data.
20432053
*/
20442054
module Csv {
2045-
private string parameterQualifiedTypeNamesToString(DataFlowCallable c) {
2046-
result =
2047-
concat(Parameter p, int i |
2048-
p = c.getParameter(i)
2049-
|
2050-
p.getType().getQualifiedName(), "," order by i
2051-
)
2052-
}
2053-
20542055
/** Holds if the summary should apply for all overrides of `c`. */
20552056
predicate isBaseCallableOrPrototype(DataFlowCallable c) {
20562057
c.getDeclaringType() instanceof Interface

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ private import semmle.code.csharp.dataflow.DataFlow
55
private import semmle.code.csharp.dataflow.ExternalFlow
66
private import semmle.code.csharp.dataflow.FlowSummary
77
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
8+
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
89
private import semmle.code.csharp.dataflow.TaintTracking
910
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
1011
private import semmle.code.csharp.security.dataflow.flowsources.Remote
@@ -23,7 +24,7 @@ class TestLibrary extends RefType {
2324
/**
2425
* An external API from either the C# Standard Library or a 3rd party library.
2526
*/
26-
class ExternalApi extends Callable {
27+
class ExternalApi extends DataFlowDispatch::DataFlowCallable {
2728
ExternalApi() { this.fromLibrary() }
2829

2930
/**
@@ -32,13 +33,13 @@ class ExternalApi extends Callable {
3233
private string getSignature() {
3334
result =
3435
this.getDeclaringType().getUnboundDeclaration() + "." + this.getName() + "(" +
35-
this.parameterTypesToString() + ")"
36+
parameterQualifiedTypeNamesToString(this) + ")"
3637
}
3738

3839
/**
3940
* Gets the namespace of this API.
4041
*/
41-
private string getNamespace() { result = this.getDeclaringType().getNamespace().toString() }
42+
private string getNamespace() { this.getDeclaringType().hasQualifiedName(result, _) }
4243

4344
/**
4445
* Gets the assembly file name containing this API.
@@ -74,7 +75,7 @@ class ExternalApi extends Callable {
7475

7576
/** Holds if this API has a supported summary. */
7677
predicate hasSummary() {
77-
this.getUnboundDeclaration() = any(SummarizedCallable sc) or
78+
this instanceof SummarizedCallable or
7879
defaultAdditionalTaintStep(this.getAnInput(), _)
7980
}
8081

csharp/ql/src/Telemetry/ExternalLibraryUsage.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from int usages, string info
1313
where
1414
usages =
1515
strictcount(Call c, ExternalApi api |
16-
c.getTarget() = api and
16+
c.getTarget().getUnboundDeclaration() = api and
1717
api.getInfoPrefix() = info and
1818
not api.isUninteresting()
1919
)

csharp/ql/src/Telemetry/SupportedExternalSinks.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ from ExternalApi api, int usages
1313
where
1414
not api.isUninteresting() and
1515
api.isSink() and
16-
usages = strictcount(Call c | c.getTarget() = api)
16+
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
1717
select api.getInfo() as info, usages order by usages desc

csharp/ql/src/Telemetry/SupportedExternalSources.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ from ExternalApi api, int usages
1313
where
1414
not api.isUninteresting() and
1515
api.isSource() and
16-
usages = strictcount(Call c | c.getTarget() = api)
16+
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
1717
select api.getInfo() as info, usages order by usages desc

csharp/ql/src/Telemetry/SupportedExternalTaint.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ from ExternalApi api, int usages
1313
where
1414
not api.isUninteresting() and
1515
api.hasSummary() and
16-
usages = strictcount(Call c | c.getTarget() = api)
16+
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
1717
select api.getInfo() as info, usages order by usages desc

csharp/ql/src/Telemetry/UnsupportedExternalAPIs.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ from ExternalApi api, int usages
1313
where
1414
not api.isUninteresting() and
1515
not api.isSupported() and
16-
usages = strictcount(Call c | c.getTarget() = api)
16+
usages = strictcount(Call c | c.getTarget().getUnboundDeclaration() = api)
1717
select api.getInfo() as info, usages order by usages desc
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| System.Private.CoreLib.dll#System.Collections.Generic#List<>.Add(object) | 2 |
1+
| System.Private.CoreLib.dll#System.Collections.Generic#List<>.Add(T) | 2 |
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| System.Private.CoreLib.dll#System#DateTime.AddYears(int) | 2 |
2-
| System.Private.CoreLib.dll#System#DateTime.AddDays(double) | 1 |
3-
| System.Private.CoreLib.dll#System#DateTime.DateTime(int, int, int) | 1 |
4-
| System.Private.CoreLib.dll#System#Guid.Parse(string) | 1 |
1+
| System.Private.CoreLib.dll#System#DateTime.AddYears(System.Int32) | 2 |
2+
| System.Private.CoreLib.dll#System#DateTime.AddDays(System.Double) | 1 |
3+
| System.Private.CoreLib.dll#System#DateTime.DateTime(System.Int32,System.Int32,System.Int32) | 1 |
4+
| System.Private.CoreLib.dll#System#Guid.Parse(System.String) | 1 |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| System.Web.cs#System.Web#HttpResponse.Write(object) | 2 |
2-
| System.Web.cs#System.Web#HttpResponse.WriteFile(string) | 1 |
1+
| System.Web.cs#System.Web#HttpResponse.Write(System.Object) | 2 |
2+
| System.Web.cs#System.Web#HttpResponse.WriteFile(System.String) | 1 |

0 commit comments

Comments
 (0)