Skip to content

Commit 6f583ba

Browse files
committed
Java: More documentation and support for field writes.
1 parent e9bfbb6 commit 6f583ba

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

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

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,57 @@
22
* INTERNAL use only. This is an experimental API subject to change without notice.
33
*
44
* Provides classes and predicates for dealing with flow models specified in CSV format.
5+
*
6+
* The CSV specification has the following columns:
7+
* - Sources:
8+
* `namespace; type; subtypes; name; signature; ext; output; kind`
9+
* - Sinks:
10+
* `namespace; type; subtypes; name; signature; ext; input; kind`
11+
* - Summaries:
12+
* `namespace; type; subtypes; name; signature; ext; input; output; kind`
13+
*
14+
* The interpretation of a row is similar to API-graphs with a left-to-right
15+
* reading.
16+
* 1. The `namespace` column selects a package.
17+
* 2. The `type` column selects a type within that package.
18+
* 3. The `subtypes` is a boolean that indicates whether to jump to an
19+
* arbitrary subtype of that type.
20+
* 4. The `name` column optionally selects a specific named member of the type.
21+
* 5. The `signature` column optionally restricts the named member. If
22+
* `signature` is blank then no such filtering is done. The format of the
23+
* signature is a comma-separated list of types enclosed in parentheses. The
24+
* types can be short names or fully qualified names (mixing these two options
25+
* is not allowed within a single signature).
26+
* 6. The `ext` column specifies additional API-graph-like edges. Currently
27+
* there are only two valid values: "" and "Annotated". The empty string has no
28+
* effect. "Annotated" applies if `name` and `signature` were left blank and
29+
* acts by selecting an element that is annotated by the annotation type
30+
* selected by the first 4 columns. This can be another member such as a field
31+
* or method, or a parameter.
32+
* 7. The `input` column specifies how data enters the element selected by the
33+
* first 6 columns, and the `output` column specifies how data leaves the
34+
* element selected by the first 6 columns. An `input` can be either "",
35+
* "Argument", "Argument[n]", "ReturnValue":
36+
* - "": Selects a write to the selected element in case this is a field.
37+
* - "Argument": Selects any argument in a call to the selected element.
38+
* - "Argument[n]": Similar to "Argument" but restricted to a specific numbered
39+
* argument (zero-indexed, and `-1` specifies the qualifier).
40+
* - "ReturnValue": Selects a value being returned by the selected element.
41+
* This requires that the selected element is a method with a body.
42+
*
43+
* An `output` can be either "", "Argument", "Argument[n]", "Parameter",
44+
* "Parameter[n]", or "ReturnValue":
45+
* - "": Selects a read of a selected field, or a selected parameter.
46+
* - "Argument": Selects the post-update value of an argument in a call to the
47+
* selected element. That is, the value of the argument after the call returns.
48+
* - "Argument[n]": Similar to "Argument" but restricted to a specific numbered
49+
* argument (zero-indexed, and `-1` specifies the qualifier).
50+
* - "Parameter": Selects the value of a parameter of the selected element.
51+
* "Parameter" is also allowed in case the selected element is already a
52+
* parameter itself.
53+
* - "Parameter[n]": Similar to "Parameter" but restricted to a specific
54+
* numbered parameter (zero-indexed, and `-1` specifies the value of `this`).
55+
* - "ReturnValue": Selects the return value of a call to the selected element.
556
*/
657

758
import java
@@ -255,7 +306,7 @@ private Element interpretElement0(
255306
m.hasName(name)
256307
|
257308
signature = "" or
258-
m.(Callable).getSignature().matches("%" + signature) or
309+
m.(Callable).getSignature() = any(string nameprefix) + signature or
259310
paramsString(m) = signature
260311
)
261312
or
@@ -419,6 +470,12 @@ private predicate interpretInput(string input, int idx, Top ref, TAstOrNode node
419470
n.asExpr() = ret.getResult() and
420471
mid = ret.getEnclosingCallable()
421472
)
473+
or
474+
exists(FieldWrite fw |
475+
c = "" and
476+
fw.getField() = mid and
477+
n.asExpr() = fw.getRHS()
478+
)
422479
)
423480
}
424481

java/ql/test/library-tests/dataflow/external-models/B.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void foo() {
99
taggedSinkMethod(argToTagged);
1010

1111
Object fieldWrite = new Object();
12-
taggedField = fieldWrite; // not currently handled
12+
taggedField = fieldWrite;
1313
}
1414

1515
Object sinkMethod() {

java/ql/test/library-tests/dataflow/external-models/sinks.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ invalidModelRow
33
| B.java:6:11:6:14 | arg1 | qltest |
44
| B.java:9:5:9:33 | this <.method> | qltest-arg |
55
| B.java:9:22:9:32 | argToTagged | qltest-arg |
6+
| B.java:12:19:12:28 | fieldWrite | qltest-nospec |
67
| B.java:17:12:17:14 | res | qltest |
78
| B.java:23:12:23:17 | resTag | qltest-retval |

0 commit comments

Comments
 (0)