C#: Simplify SummarizedCallableDefaultClearsContent

This commit is contained in:
Tom Hvitved
2021-10-20 10:47:47 +02:00
parent dd138b0429
commit 53d4d72fe5
3 changed files with 13 additions and 4 deletions

View File

@@ -79,14 +79,14 @@ module SummaryComponentStack {
class SummarizedCallable = Impl::Public::SummarizedCallable;
private class SummarizedCallableDefaultClearsContent extends Impl::Public::SummarizedCallable {
SummarizedCallable c;
SummarizedCallableDefaultClearsContent() { this = c }
SummarizedCallableDefaultClearsContent() {
this instanceof Impl::Public::SummarizedCallable or none()
}
// By default, we assume that all stores into arguments are definite
override predicate clearsContent(int i, DataFlow::Content content) {
exists(SummaryComponentStack output |
c.propagatesFlow(_, output, _) and
this.propagatesFlow(_, output, _) and
output.drop(_) =
SummaryComponentStack::push(SummaryComponent::content(content),
SummaryComponentStack::argument(i)) and

View File

@@ -21,3 +21,6 @@ summarySetterStep
| Steps.cs:30:34:30:34 | 0 | Steps.cs:30:13:30:16 | [post] this access | Steps.cs:57:13:57:17 | field Field |
| Steps.cs:34:37:34:37 | 0 | Steps.cs:34:13:34:16 | [post] this access | Steps.cs:63:13:63:20 | property Property |
| Steps.cs:38:36:38:36 | 0 | Steps.cs:38:13:38:16 | [post] this access | file://:0:0:0:0 | element |
clearsContent
| Steps.cs:61:14:61:28 | StepFieldSetter | Steps.cs:57:13:57:17 | field Field | -1 |
| Steps.cs:67:14:67:31 | StepPropertySetter | Steps.cs:63:13:63:20 | property Property | -1 |

View File

@@ -1,6 +1,7 @@
import csharp
import DataFlow
import semmle.code.csharp.dataflow.ExternalFlow
import semmle.code.csharp.dataflow.FlowSummary
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
import CsvValidation
@@ -40,3 +41,8 @@ query predicate summaryGetterStep(DataFlow::Node arg, DataFlow::Node out, Conten
query predicate summarySetterStep(DataFlow::Node arg, DataFlow::Node out, Content c) {
FlowSummaryImpl::Private::Steps::summarySetterStep(arg, c, out)
}
query predicate clearsContent(SummarizedCallable c, DataFlow::Content k, int i) {
c.clearsContent(i, k) and
c.fromSource()
}