Skip to content

Commit bf958ff

Browse files
authored
Merge pull request #9255 from michaelnebel/csharp/test-clearscontent
C#: Remove default clears content.
2 parents c82ab68 + 217c414 commit bf958ff

File tree

6 files changed

+21
-28
lines changed

6 files changed

+21
-28
lines changed

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,6 @@ private class RecordConstructorFlow extends SummarizedCallable {
139139
}
140140
}
141141

142-
private class SummarizedCallableDefaultClearsContent extends Impl::Public::SummarizedCallable {
143-
SummarizedCallableDefaultClearsContent() {
144-
this instanceof Impl::Public::SummarizedCallable or none()
145-
}
146-
147-
// By default, we assume that all stores into arguments are definite
148-
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {
149-
exists(SummaryComponentStack output, SummaryComponent target |
150-
this.propagatesFlow(_, output, _) and
151-
output.drop(_) =
152-
SummaryComponentStack::push(SummaryComponent::content(content),
153-
SummaryComponentStack::singleton(target)) and
154-
not content instanceof DataFlow::ElementContent
155-
|
156-
target = SummaryComponent::argument(pos.getPosition())
157-
or
158-
target = SummaryComponent::qualifier() and
159-
pos.isThisParameter()
160-
)
161-
}
162-
}
163-
164142
class RequiredSummaryComponentStack = Impl::Public::RequiredSummaryComponentStack;
165143

166144
private class RecordConstructorFlowRequiredSummaryComponentStack extends RequiredSummaryComponentStack {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,8 @@ module Private {
933933
summaryElement(this, inSpec, outSpec, kind, false)
934934
or
935935
summaryElement(this, inSpec, outSpec, kind, true) and
936-
not summaryElement(this, _, _, _, false)
936+
not summaryElement(this, _, _, _, false) and
937+
not this.clearsContent(_, _)
937938
}
938939

939940
override predicate propagatesFlow(

csharp/ql/test/library-tests/dataflow/external-models/steps.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ summarySetterStep
2020
| Steps.cs:34:37:34:37 | 0 | Steps.cs:34:13:34:16 | [post] this access | Steps.cs:63:13:63:20 | property Property |
2121
| Steps.cs:38:36:38:36 | 0 | Steps.cs:38:13:38:16 | [post] this access | file://:0:0:0:0 | element |
2222
clearsContent
23-
| Steps.cs:61:14:61:28 | StepFieldSetter | Steps.cs:57:13:57:17 | field Field | this |
24-
| Steps.cs:67:14:67:31 | StepPropertySetter | Steps.cs:63:13:63:20 | property Property | this |
23+
| Steps.cs:61:14:61:28 | StepFieldSetter | file://:0:0:0:0 | element | this |
24+
| Steps.cs:67:14:67:31 | StepPropertySetter | file://:0:0:0:0 | element | this |

csharp/ql/test/library-tests/dataflow/external-models/steps.ql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import semmle.code.csharp.dataflow.FlowSummary
55
import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
66
import CsvValidation
77

8-
class SummaryModelTest extends SummaryModelCsv {
8+
private class SummaryModelTest extends SummaryModelCsv {
99
override predicate row(string row) {
1010
row =
1111
[
@@ -28,6 +28,18 @@ class SummaryModelTest extends SummaryModelCsv {
2828
}
2929
}
3030

31+
private class SummarizedCallableClear extends SummarizedCallable {
32+
SummarizedCallableClear() {
33+
this.getName() = ["StepPropertySetter", "StepFieldSetter"] and
34+
this.getFile().getBaseName() = "Steps.cs"
35+
}
36+
37+
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {
38+
pos.isThisParameter() and
39+
content instanceof DataFlow::ElementContent
40+
}
41+
}
42+
3143
query predicate summaryThroughStep(
3244
DataFlow::Node node1, DataFlow::Node node2, boolean preservesValue
3345
) {

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,8 @@ module Private {
933933
summaryElement(this, inSpec, outSpec, kind, false)
934934
or
935935
summaryElement(this, inSpec, outSpec, kind, true) and
936-
not summaryElement(this, _, _, _, false)
936+
not summaryElement(this, _, _, _, false) and
937+
not this.clearsContent(_, _)
937938
}
938939

939940
override predicate propagatesFlow(

ruby/ql/lib/codeql/ruby/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,8 @@ module Private {
933933
summaryElement(this, inSpec, outSpec, kind, false)
934934
or
935935
summaryElement(this, inSpec, outSpec, kind, true) and
936-
not summaryElement(this, _, _, _, false)
936+
not summaryElement(this, _, _, _, false) and
937+
not this.clearsContent(_, _)
937938
}
938939

939940
override predicate propagatesFlow(

0 commit comments

Comments
 (0)