Skip to content

Commit aa82d0b

Browse files
committed
Java: Make Content public as DataFlow::Content.
1 parent 8088032 commit aa82d0b

File tree

4 files changed

+72
-66
lines changed

4 files changed

+72
-66
lines changed

java/ql/src/semmle/code/java/dataflow/FlowSummary.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java
66
private import internal.FlowSummaryImpl as Impl
77
private import internal.DataFlowDispatch
8-
private import internal.DataFlowPrivate
8+
private import internal.DataFlowUtil
99

1010
// import all instances of SummarizedCallable below
1111
private module Summaries {

java/ql/src/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -83,56 +83,6 @@ private predicate instanceFieldAssign(Expr src, FieldAccess fa) {
8383
)
8484
}
8585

86-
private newtype TContent =
87-
TFieldContent(InstanceField f) or
88-
TArrayContent() or
89-
TCollectionContent() or
90-
TMapKeyContent() or
91-
TMapValueContent()
92-
93-
/**
94-
* A reference contained in an object. Examples include instance fields, the
95-
* contents of a collection object, or the contents of an array.
96-
*/
97-
class Content extends TContent {
98-
/** Gets a textual representation of this element. */
99-
abstract string toString();
100-
101-
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
102-
path = "" and sl = 0 and sc = 0 and el = 0 and ec = 0
103-
}
104-
}
105-
106-
class FieldContent extends Content, TFieldContent {
107-
InstanceField f;
108-
109-
FieldContent() { this = TFieldContent(f) }
110-
111-
InstanceField getField() { result = f }
112-
113-
override string toString() { result = f.toString() }
114-
115-
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
116-
f.getLocation().hasLocationInfo(path, sl, sc, el, ec)
117-
}
118-
}
119-
120-
class ArrayContent extends Content, TArrayContent {
121-
override string toString() { result = "[]" }
122-
}
123-
124-
class CollectionContent extends Content, TCollectionContent {
125-
override string toString() { result = "<element>" }
126-
}
127-
128-
class MapKeyContent extends Content, TMapKeyContent {
129-
override string toString() { result = "<map.key>" }
130-
}
131-
132-
class MapValueContent extends Content, TMapValueContent {
133-
override string toString() { result = "<map.value>" }
134-
}
135-
13686
/**
13787
* Holds if data can flow from `node1` to `node2` via an assignment to `f`.
13888
* Thus, `node2` references an object with a field `f` that contains the

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,62 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
157157
FlowSummaryImpl::Private::Steps::summaryLocalStep(node1, node2, true)
158158
}
159159

160+
private newtype TContent =
161+
TFieldContent(InstanceField f) or
162+
TArrayContent() or
163+
TCollectionContent() or
164+
TMapKeyContent() or
165+
TMapValueContent()
166+
167+
/**
168+
* A description of the way data may be stored inside an object. Examples
169+
* include instance fields, the contents of a collection object, or the contents
170+
* of an array.
171+
*/
172+
class Content extends TContent {
173+
/** Gets a textual representation of this element. */
174+
abstract string toString();
175+
176+
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
177+
path = "" and sl = 0 and sc = 0 and el = 0 and ec = 0
178+
}
179+
}
180+
181+
/** A reference through an instance field. */
182+
class FieldContent extends Content, TFieldContent {
183+
InstanceField f;
184+
185+
FieldContent() { this = TFieldContent(f) }
186+
187+
InstanceField getField() { result = f }
188+
189+
override string toString() { result = f.toString() }
190+
191+
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
192+
f.getLocation().hasLocationInfo(path, sl, sc, el, ec)
193+
}
194+
}
195+
196+
/** A reference through an array. */
197+
class ArrayContent extends Content, TArrayContent {
198+
override string toString() { result = "[]" }
199+
}
200+
201+
/** A reference through the contents of some collection-like container. */
202+
class CollectionContent extends Content, TCollectionContent {
203+
override string toString() { result = "<element>" }
204+
}
205+
206+
/** A reference through a map key. */
207+
class MapKeyContent extends Content, TMapKeyContent {
208+
override string toString() { result = "<map.key>" }
209+
}
210+
211+
/** A reference through a map value. */
212+
class MapValueContent extends Content, TMapValueContent {
213+
override string toString() { result = "<map.value>" }
214+
}
215+
160216
/**
161217
* A guard that validates some expression.
162218
*

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ private module Cached {
6161
localAdditionalTaintUpdateStep(src.asExpr(),
6262
sink.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr())
6363
or
64-
exists(Content f |
64+
exists(DataFlow::Content f |
6565
readStep(src, f, sink) and
6666
not sink.getTypeBound() instanceof PrimitiveType and
6767
not sink.getTypeBound() instanceof BoxedType and
6868
not sink.getTypeBound() instanceof NumberType
6969
|
70-
f instanceof ArrayContent or
71-
f instanceof CollectionContent or
72-
f instanceof MapKeyContent or
73-
f instanceof MapValueContent
70+
f instanceof DataFlow::ArrayContent or
71+
f instanceof DataFlow::CollectionContent or
72+
f instanceof DataFlow::MapKeyContent or
73+
f instanceof DataFlow::MapValueContent
7474
)
7575
or
7676
FlowSummaryImpl::Private::Steps::summaryLocalStep(src, sink, false)
@@ -122,7 +122,7 @@ private module StoreTaintSteps {
122122

123123
override predicate isSink(DataFlow::Node n) { none() }
124124

125-
private predicate needsTaintStore(RefType container, Type elem, Content f) {
125+
private predicate needsTaintStore(RefType container, Type elem, DataFlow::Content f) {
126126
exists(DataFlow::Node arg |
127127
(isSink(arg) or isAdditionalTaintStep(arg, _)) and
128128
(arg.asExpr() instanceof Argument or arg instanceof ArgumentNode) and
@@ -131,18 +131,18 @@ private module StoreTaintSteps {
131131
needsTaintStore(_, container, _)
132132
|
133133
container.(Array).getComponentType() = elem and
134-
f instanceof ArrayContent
134+
f instanceof DataFlow::ArrayContent
135135
or
136136
container.(CollectionType).getElementType() = elem and
137-
f instanceof CollectionContent
137+
f instanceof DataFlow::CollectionContent
138138
or
139139
container.(MapType).getValueType() = elem and
140-
f instanceof MapValueContent
140+
f instanceof DataFlow::MapValueContent
141141
)
142142
}
143143

144144
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
145-
exists(Content f, Type elem |
145+
exists(DataFlow::Content f, Type elem |
146146
storeStep(node1, f, node2) and
147147
needsTaintStore(_, elem, f) and
148148
not exists(Type srctyp | srctyp = node1.getTypeBound() | not compatibleTypes(srctyp, elem))
@@ -157,7 +157,7 @@ private module StoreTaintSteps {
157157

158158
override predicate isSink(DataFlow::Node n) { none() }
159159

160-
private predicate needsTaintStore(RefType container, Type elem, Content f) {
160+
private predicate needsTaintStore(RefType container, Type elem, DataFlow::Content f) {
161161
exists(DataFlow::Node arg |
162162
(isSink(arg) or isAdditionalTaintStep(arg, _)) and
163163
(arg.asExpr() instanceof Argument or arg instanceof ArgumentNode) and
@@ -166,18 +166,18 @@ private module StoreTaintSteps {
166166
needsTaintStore(_, container, _)
167167
|
168168
container.(Array).getComponentType() = elem and
169-
f instanceof ArrayContent
169+
f instanceof DataFlow::ArrayContent
170170
or
171171
container.(CollectionType).getElementType() = elem and
172-
f instanceof CollectionContent
172+
f instanceof DataFlow::CollectionContent
173173
or
174174
container.(MapType).getValueType() = elem and
175-
f instanceof MapValueContent
175+
f instanceof DataFlow::MapValueContent
176176
)
177177
}
178178

179179
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
180-
exists(Content f, Type elem |
180+
exists(DataFlow::Content f, Type elem |
181181
storeStep(node1, f, node2) and
182182
needsTaintStore(_, elem, f) and
183183
not exists(Type srctyp | srctyp = node1.getTypeBound() | not compatibleTypes(srctyp, elem))

0 commit comments

Comments
 (0)