Skip to content

Commit 9b47249

Browse files
committed
C#: Migrate the legacy clearContent flow summaries to the new framework.
1 parent fd317c2 commit 9b47249

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/LibraryTypeDataFlow.qll

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,3 @@ private module FrameworkDataFlowAdaptor {
132132
override predicate required(SummaryComponent c) { c = head }
133133
}
134134
}
135-
136-
/** Data flow for `System.Text.StringBuilder`. */
137-
class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringBuilderClass {
138-
override predicate clearsContent(
139-
CallableFlowSource source, Content content, SourceDeclarationCallable callable
140-
) {
141-
source = TCallableFlowSourceQualifier() and
142-
callable = this.getAMethod("Clear") and
143-
content instanceof ElementContent
144-
}
145-
}
146-
147-
/** Data flow for `System.Collections.IEnumerable` (and sub types). */
148-
class IEnumerableFlow extends LibraryTypeDataFlow, RefType {
149-
IEnumerableFlow() { this.getABaseType*() instanceof SystemCollectionsIEnumerableInterface }
150-
151-
override predicate clearsContent(
152-
CallableFlowSource source, Content content, SourceDeclarationCallable callable
153-
) {
154-
source = TCallableFlowSourceQualifier() and
155-
callable = this.getAMethod("Clear") and
156-
content instanceof ElementContent
157-
}
158-
}

csharp/ql/lib/semmle/code/csharp/frameworks/system/Collections.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import csharp
44
private import semmle.code.csharp.frameworks.System
55
private import semmle.code.csharp.dataflow.ExternalFlow
6+
private import semmle.code.csharp.dataflow.FlowSummary
67

78
/** The `System.Collections` namespace. */
89
class SystemCollectionsNamespace extends Namespace {
@@ -45,6 +46,20 @@ private class SystemCollectionIEnumerableFlowModelCsv extends SummaryModelCsv {
4546
}
4647
}
4748

49+
/** Clear content for Clear methods in all subtypes of `System.Collections.IEnumerable`. */
50+
private class SystemCollectionsIEnumerableClearFlow extends SummarizedCallable {
51+
SystemCollectionsIEnumerableClearFlow() {
52+
this.getDeclaringType().(RefType).getABaseType*() instanceof
53+
SystemCollectionsIEnumerableInterface and
54+
this.hasName("Clear")
55+
}
56+
57+
override predicate clearsContent(ParameterPosition pos, DataFlow::Content content) {
58+
pos.getPosition() = -1 and
59+
content instanceof DataFlow::ElementContent
60+
}
61+
}
62+
4863
/** The `System.Collections.IEnumerator` interface. */
4964
class SystemCollectionsIEnumeratorInterface extends SystemCollectionsInterface {
5065
SystemCollectionsIEnumeratorInterface() { this.hasName("IEnumerator") }

csharp/ql/lib/semmle/code/csharp/frameworks/system/Text.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import csharp
44
private import semmle.code.csharp.frameworks.System
55
private import semmle.code.csharp.dataflow.ExternalFlow
6+
private import semmle.code.csharp.dataflow.FlowSummary
67

78
/** The `System.Text` namespace. */
89
class SystemTextNamespace extends Namespace {
@@ -25,6 +26,19 @@ class SystemTextStringBuilderClass extends SystemTextClass {
2526
Method getAppendFormatMethod() { result = this.getAMethod("AppendFormat") }
2627
}
2728

29+
/** Clear content for `System.Text.StringBuilder.Clear`. */
30+
private class SystemTextStringBuilderClearFlow extends SummarizedCallable {
31+
SystemTextStringBuilderClearFlow() {
32+
this.getDeclaringType() instanceof SystemTextStringBuilderClass and
33+
this.hasName("Clear")
34+
}
35+
36+
override predicate clearsContent(ParameterPosition pos, DataFlow::Content content) {
37+
pos.getPosition() = -1 and
38+
content instanceof DataFlow::ElementContent
39+
}
40+
}
41+
2842
/** Data flow for `System.Text.StringBuilder`. */
2943
private class SystemTextStringBuilderFlowModelCsv extends SummaryModelCsv {
3044
override predicate row(string row) {

0 commit comments

Comments
 (0)