Skip to content

Commit 7113c1b

Browse files
committed
C#: Implement ContentSet
1 parent b91858e commit 7113c1b

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private class SummarizedCallableDefaultClearsContent extends Impl::Public::Summa
144144
}
145145

146146
// By default, we assume that all stores into arguments are definite
147-
override predicate clearsContent(ParameterPosition pos, DataFlow::Content content) {
147+
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {
148148
exists(SummaryComponentStack output, SummaryComponent target |
149149
this.propagatesFlow(_, output, _) and
150150
output.drop(_) =

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,23 @@ class ElementContent extends Content, TElementContent {
252252

253253
override Location getLocation() { result instanceof EmptyLocation }
254254
}
255+
256+
/**
257+
* An entity that represents a set of `Content`s.
258+
*
259+
* The set may be interpreted differently depending on whether it is
260+
* stored into (`getAStoreContent`) or read from (`getAReadContent`).
261+
*/
262+
class ContentSet instanceof Content {
263+
/** Gets a content that may be stored into when storing into this set. */
264+
Content getAStoreContent() { result = this }
265+
266+
/** Gets a content that may be read from when reading from this set. */
267+
Content getAReadContent() { result = this }
268+
269+
/** Gets a textual representation of this content set. */
270+
string toString() { result = super.toString() }
271+
272+
/** Gets the location of this content set. */
273+
Location getLocation() { result = super.getLocation() }
274+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private class SystemCollectionsIEnumerableClearFlow extends SummarizedCallable {
5454
this.hasName("Clear")
5555
}
5656

57-
override predicate clearsContent(ParameterPosition pos, DataFlow::Content content) {
57+
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {
5858
pos.isThisParameter() and
5959
content instanceof DataFlow::ElementContent
6060
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private class SystemTextStringBuilderClearFlow extends SummarizedCallable {
3232
this = any(SystemTextStringBuilderClass s).getAMethod("Clear")
3333
}
3434

35-
override predicate clearsContent(ParameterPosition pos, DataFlow::Content content) {
35+
override predicate clearsContent(ParameterPosition pos, DataFlow::ContentSet content) {
3636
pos.isThisParameter() and
3737
content instanceof DataFlow::ElementContent
3838
}

0 commit comments

Comments
 (0)