Skip to content

Commit 665e3c9

Browse files
committed
C#: Re-factor containerContent into standalone predicate in DataFlow library.
1 parent 5d03e51 commit 665e3c9

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

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

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

253253
override Location getLocation() { result instanceof EmptyLocation }
254254
}
255+
256+
/**
257+
* Holds if the the content `c` is a container.
258+
*/
259+
predicate containerContent(DataFlow::Content c) { c instanceof DataFlow::ElementContent }

csharp/ql/src/utils/model-generator/ModelGeneratorUtilsSpecific.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
6666
else any()
6767
)
6868
or
69-
exists(DataFlow::Content f | storeStep(node1, f, node2) | f instanceof DataFlow::ElementContent)
69+
exists(DataFlow::Content f | storeStep(node1, f, node2) | DataFlow::containerContent(f))
7070
}
7171

7272
predicate isRelevantContent(DataFlow::Content f) {
7373
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
7474
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
75-
f instanceof DataFlow::ElementContent
75+
DataFlow::containerContent(f)
7676
}
7777

7878
private predicate isPrimitiveTypeUsedForBulkData(Type t) {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ class SyntheticFieldContent extends Content, TSyntheticFieldContent {
256256
override string toString() { result = s.toString() }
257257
}
258258

259+
/**
260+
* Holds if the the content `c` is a container.
261+
*/
262+
predicate containerContent(Content c) {
263+
c instanceof ArrayContent or
264+
c instanceof CollectionContent or
265+
c instanceof MapKeyContent or
266+
c instanceof MapValueContent
267+
}
268+
259269
/**
260270
* A guard that validates some expression.
261271
*

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,14 @@ private module Cached {
5454
FlowSummaryImpl::Private::Steps::summaryThroughStep(src, sink, false)
5555
or
5656
// Treat container flow as taint for the local taint flow relation
57-
exists(DataFlow::Content c | containerContent(c) |
57+
exists(DataFlow::Content c | DataFlow::containerContent(c) |
5858
readStep(src, c, sink) or
5959
storeStep(src, c, sink) or
6060
FlowSummaryImpl::Private::Steps::summaryGetterStep(src, c, sink) or
6161
FlowSummaryImpl::Private::Steps::summarySetterStep(src, c, sink)
6262
)
6363
}
6464

65-
private predicate containerContent(DataFlow::Content c) {
66-
c instanceof DataFlow::ArrayContent or
67-
c instanceof DataFlow::CollectionContent or
68-
c instanceof DataFlow::MapKeyContent or
69-
c instanceof DataFlow::MapValueContent
70-
}
71-
7265
/**
7366
* Holds if taint can flow in one local step from `src` to `sink` excluding
7467
* local data flow steps. That is, `src` and `sink` are likely to represent
@@ -87,7 +80,7 @@ private module Cached {
8780
not sink.getTypeBound() instanceof BoxedType and
8881
not sink.getTypeBound() instanceof NumberType and
8982
(
90-
containerContent(f)
83+
DataFlow::containerContent(f)
9184
or
9285
f instanceof TaintInheritingContent
9386
)

java/ql/src/utils/model-generator/ModelGeneratorUtilsSpecific.qll

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,13 @@ predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
122122
else any()
123123
)
124124
or
125-
exists(DataFlow::Content f | storeStep(node1, f, node2) |
126-
f instanceof DataFlow::ArrayContent or
127-
f instanceof DataFlow::CollectionContent or
128-
f instanceof DataFlow::MapKeyContent or
129-
f instanceof DataFlow::MapValueContent
130-
)
125+
exists(DataFlow::Content f | storeStep(node1, f, node2) | DataFlow::containerContent(f))
131126
}
132127

133128
predicate isRelevantContent(DataFlow::Content f) {
134129
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
135130
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
136-
f instanceof DataFlow::ArrayContent or
137-
f instanceof DataFlow::CollectionContent or
138-
f instanceof DataFlow::MapKeyContent or
139-
f instanceof DataFlow::MapValueContent
131+
DataFlow::containerContent(f)
140132
}
141133

142134
private string parameterAccess(Parameter p) {

0 commit comments

Comments
 (0)