Skip to content

Commit b91858e

Browse files
committed
Java: Implement ContentSet
1 parent d99bb65 commit b91858e

File tree

8 files changed

+35
-13
lines changed

8 files changed

+35
-13
lines changed

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

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

259+
/**
260+
* An entity that represents a set of `Content`s.
261+
*
262+
* The set may be interpreted differently depending on whether it is
263+
* stored into (`getAStoreContent`) or read from (`getAReadContent`).
264+
*/
265+
class ContentSet instanceof Content {
266+
/** Gets a content that may be stored into when storing into this set. */
267+
Content getAStoreContent() { result = this }
268+
269+
/** Gets a content that may be read from when reading from this set. */
270+
Content getAReadContent() { result = this }
271+
272+
/** Gets a textual representation of this content set. */
273+
string toString() { result = super.toString() }
274+
275+
/**
276+
* Holds if this element is at the specified location.
277+
* The location spans column `startcolumn` of line `startline` to
278+
* column `endcolumn` of line `endline` in file `filepath`.
279+
* For more information, see
280+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
281+
*/
282+
predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
283+
super.hasLocationInfo(path, sl, sc, el, ec)
284+
}
285+
}
286+
259287
/**
260288
* A guard that validates some expression.
261289
*

java/ql/lib/semmle/code/java/security/AndroidSensitiveCommunicationQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class SensitiveCommunicationConfig extends TaintTracking::Configuration {
142142
*/
143143
override predicate isSanitizer(DataFlow::Node node) { node instanceof ExplicitIntentSanitizer }
144144

145-
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::Content c) {
145+
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
146146
super.allowImplicitRead(node, c)
147147
or
148148
this.isSink(node)

java/ql/lib/semmle/code/java/security/ImplicitPendingIntentsQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ImplicitPendingIntentStartConf extends TaintTracking::Configuration {
3636
any(ImplicitPendingIntentAdditionalTaintStep c).step(node1, state1, node2, state2)
3737
}
3838

39-
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::Content c) {
39+
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
4040
super.allowImplicitRead(node, c)
4141
or
4242
this.isSink(node, _) and

java/ql/lib/semmle/code/java/security/InsecureTrustManagerQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class InsecureTrustManagerConfiguration extends DataFlow::Configuration {
1717

1818
override predicate isSink(DataFlow::Node sink) { sink instanceof InsecureTrustManagerSink }
1919

20-
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::Content c) {
20+
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
2121
(this.isSink(node) or this.isAdditionalFlowStep(node, _)) and
2222
node.getType() instanceof Array and
2323
c instanceof DataFlow::ArrayContent

java/ql/src/experimental/Security/CWE/CWE-200/AndroidFileIntentSource.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GetContentIntentConfig extends TaintTracking2::Configuration {
4040
)
4141
}
4242

43-
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::Content content) {
43+
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet content) {
4444
super.allowImplicitRead(node, content)
4545
or
4646
// Allow the wrapped intent created by Intent.getChooser to be consumed

java/ql/test/experimental/query-tests/security/CWE-470/UnsafeReflection.expected

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
edges
2-
| UnsafeReflection.java:21:28:21:60 | getParameter(...) : String | UnsafeReflection.java:25:29:25:59 | getDeclaredConstructors(...) : Constructor[] |
32
| UnsafeReflection.java:21:28:21:60 | getParameter(...) : String | UnsafeReflection.java:25:29:25:62 | ...[...] |
43
| UnsafeReflection.java:22:33:22:70 | getParameter(...) : String | UnsafeReflection.java:25:76:25:89 | parameterValue |
5-
| UnsafeReflection.java:25:29:25:59 | getDeclaredConstructors(...) : Constructor[] | UnsafeReflection.java:25:29:25:62 | ...[...] |
6-
| UnsafeReflection.java:33:28:33:60 | getParameter(...) : String | UnsafeReflection.java:39:13:39:38 | getDeclaredMethods(...) : Method[] |
74
| UnsafeReflection.java:33:28:33:60 | getParameter(...) : String | UnsafeReflection.java:39:13:39:41 | ...[...] |
85
| UnsafeReflection.java:33:28:33:60 | getParameter(...) : String | UnsafeReflection.java:39:50:39:55 | object |
96
| UnsafeReflection.java:34:33:34:70 | getParameter(...) : String | UnsafeReflection.java:39:58:39:71 | parameterValue |
10-
| UnsafeReflection.java:39:13:39:38 | getDeclaredMethods(...) : Method[] | UnsafeReflection.java:39:13:39:41 | ...[...] |
117
| UnsafeReflection.java:46:24:46:82 | beanIdOrClassName : String | UnsafeReflection.java:53:30:53:46 | beanIdOrClassName : String |
128
| UnsafeReflection.java:46:132:46:168 | body : Map | UnsafeReflection.java:49:37:49:40 | body : Map |
139
| UnsafeReflection.java:49:23:49:59 | (...)... : Object | UnsafeReflection.java:53:67:53:73 | rawData : Object |
@@ -24,12 +20,10 @@ edges
2420
nodes
2521
| UnsafeReflection.java:21:28:21:60 | getParameter(...) : String | semmle.label | getParameter(...) : String |
2622
| UnsafeReflection.java:22:33:22:70 | getParameter(...) : String | semmle.label | getParameter(...) : String |
27-
| UnsafeReflection.java:25:29:25:59 | getDeclaredConstructors(...) : Constructor[] | semmle.label | getDeclaredConstructors(...) : Constructor[] |
2823
| UnsafeReflection.java:25:29:25:62 | ...[...] | semmle.label | ...[...] |
2924
| UnsafeReflection.java:25:76:25:89 | parameterValue | semmle.label | parameterValue |
3025
| UnsafeReflection.java:33:28:33:60 | getParameter(...) : String | semmle.label | getParameter(...) : String |
3126
| UnsafeReflection.java:34:33:34:70 | getParameter(...) : String | semmle.label | getParameter(...) : String |
32-
| UnsafeReflection.java:39:13:39:38 | getDeclaredMethods(...) : Method[] | semmle.label | getDeclaredMethods(...) : Method[] |
3327
| UnsafeReflection.java:39:13:39:41 | ...[...] | semmle.label | ...[...] |
3428
| UnsafeReflection.java:39:50:39:55 | object | semmle.label | object |
3529
| UnsafeReflection.java:39:58:39:71 | parameterValue | semmle.label | parameterValue |

java/ql/test/library-tests/dataflow/getter/getter.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import semmle.code.java.dataflow.internal.DataFlowImplCommon
33
import semmle.code.java.dataflow.internal.DataFlowImplSpecific::Public
44
import semmle.code.java.dataflow.internal.DataFlowImplSpecific::Private
55

6-
from Node n1, Content f, Node n2
6+
from Node n1, ContentSet f, Node n2
77
where
88
(
9-
read(n1, f, n2) or
9+
readSet(n1, f, n2) or
1010
getterStep(n1, f, n2)
1111
) and
1212
n1.getEnclosingCallable().fromSource()

java/ql/test/library-tests/frameworks/android/slice/test.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SliceValueFlowConf extends DefaultValueFlowConf {
99
}
1010

1111
class SliceTaintFlowConf extends DefaultTaintFlowConf {
12-
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::Content c) {
12+
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
1313
super.allowImplicitRead(node, c)
1414
or
1515
isSink(node) and

0 commit comments

Comments
 (0)