C#: Migrate the legacy clearContent flow summaries to the new framework.

This commit is contained in:
Michael Nebel
2022-01-04 16:52:02 +01:00
parent fd317c2e7b
commit 9b47249f6a
3 changed files with 29 additions and 24 deletions

View File

@@ -132,27 +132,3 @@ private module FrameworkDataFlowAdaptor {
override predicate required(SummaryComponent c) { c = head }
}
}
/** Data flow for `System.Text.StringBuilder`. */
class SystemTextStringBuilderFlow extends LibraryTypeDataFlow, SystemTextStringBuilderClass {
override predicate clearsContent(
CallableFlowSource source, Content content, SourceDeclarationCallable callable
) {
source = TCallableFlowSourceQualifier() and
callable = this.getAMethod("Clear") and
content instanceof ElementContent
}
}
/** Data flow for `System.Collections.IEnumerable` (and sub types). */
class IEnumerableFlow extends LibraryTypeDataFlow, RefType {
IEnumerableFlow() { this.getABaseType*() instanceof SystemCollectionsIEnumerableInterface }
override predicate clearsContent(
CallableFlowSource source, Content content, SourceDeclarationCallable callable
) {
source = TCallableFlowSourceQualifier() and
callable = this.getAMethod("Clear") and
content instanceof ElementContent
}
}

View File

@@ -3,6 +3,7 @@
import csharp
private import semmle.code.csharp.frameworks.System
private import semmle.code.csharp.dataflow.ExternalFlow
private import semmle.code.csharp.dataflow.FlowSummary
/** The `System.Collections` namespace. */
class SystemCollectionsNamespace extends Namespace {
@@ -45,6 +46,20 @@ private class SystemCollectionIEnumerableFlowModelCsv extends SummaryModelCsv {
}
}
/** Clear content for Clear methods in all subtypes of `System.Collections.IEnumerable`. */
private class SystemCollectionsIEnumerableClearFlow extends SummarizedCallable {
SystemCollectionsIEnumerableClearFlow() {
this.getDeclaringType().(RefType).getABaseType*() instanceof
SystemCollectionsIEnumerableInterface and
this.hasName("Clear")
}
override predicate clearsContent(ParameterPosition pos, DataFlow::Content content) {
pos.getPosition() = -1 and
content instanceof DataFlow::ElementContent
}
}
/** The `System.Collections.IEnumerator` interface. */
class SystemCollectionsIEnumeratorInterface extends SystemCollectionsInterface {
SystemCollectionsIEnumeratorInterface() { this.hasName("IEnumerator") }

View File

@@ -3,6 +3,7 @@
import csharp
private import semmle.code.csharp.frameworks.System
private import semmle.code.csharp.dataflow.ExternalFlow
private import semmle.code.csharp.dataflow.FlowSummary
/** The `System.Text` namespace. */
class SystemTextNamespace extends Namespace {
@@ -25,6 +26,19 @@ class SystemTextStringBuilderClass extends SystemTextClass {
Method getAppendFormatMethod() { result = this.getAMethod("AppendFormat") }
}
/** Clear content for `System.Text.StringBuilder.Clear`. */
private class SystemTextStringBuilderClearFlow extends SummarizedCallable {
SystemTextStringBuilderClearFlow() {
this.getDeclaringType() instanceof SystemTextStringBuilderClass and
this.hasName("Clear")
}
override predicate clearsContent(ParameterPosition pos, DataFlow::Content content) {
pos.getPosition() = -1 and
content instanceof DataFlow::ElementContent
}
}
/** Data flow for `System.Text.StringBuilder`. */
private class SystemTextStringBuilderFlowModelCsv extends SummaryModelCsv {
override predicate row(string row) {