Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: Add support for flow through side-effects on static fields. #16500

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: majorAnalysis
---
* Added support for data flow through side-effects on static fields. For example, when a static field containing an array is updated.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ private predicate fieldStep(Node node1, Node node2) {
exists(Field f |
// Taint fields through assigned values only if they're static
f.isStatic() and
f.getAnAssignedValue() = node1.asExpr() and
node2.(FieldValueNode).getField() = f
|
f.getAnAssignedValue() = node1.asExpr()
or
f.getAnAccess() = node1.(PostUpdateNode).getPreUpdateNode().asExpr()
)
or
exists(Field f, FieldRead fr |
Expand Down
21 changes: 21 additions & 0 deletions java/ql/test/library-tests/dataflow/fields/G.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class G {
static Object[] f;

void sink(Object o) { }

void runsink() {
sink(f[0]);
}

void test1() {
f[0] = new Object();
}

void test2() {
addObj(f);
}

void addObj(Object[] xs) {
xs[0] = new Object();
}
}
2 changes: 2 additions & 0 deletions java/ql/test/library-tests/dataflow/fields/flow.expected
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@
| F.java:5:14:5:25 | new Object(...) | F.java:20:10:20:17 | f.Field1 |
| F.java:10:16:10:27 | new Object(...) | F.java:15:10:15:17 | f.Field1 |
| F.java:24:9:24:20 | new Object(...) | F.java:33:10:33:17 | f.Field1 |
| G.java:11:12:11:23 | new Object(...) | G.java:7:10:7:13 | ...[...] |
| G.java:19:13:19:24 | new Object(...) | G.java:7:10:7:13 | ...[...] |