Skip to content

Commit d5f101d

Browse files
committed
Add implicit read FlowState test
1 parent e3948e6 commit d5f101d

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

java/ql/test/library-tests/dataflow/state/A.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
import java.util.Map;
12
import java.util.function.*;
23

34
public class A {
4-
Object source(String state) { return null; }
5+
Object source(String state) {
6+
return null;
7+
}
58

6-
void sink(Object x, String state) { }
9+
void sink(Object x, String state) {}
710

8-
void stateBarrier(Object x, String state) { }
11+
void stateBarrier(Object x, String state) {}
912

10-
Object step(Object x, String s1, String s2) { return null; }
13+
Object step(Object x, String s1, String s2) {
14+
return null;
15+
}
1116

12-
void check(Object x) { }
17+
void check(Object x) {}
1318

1419
void test1() {
1520
Object x = source("A");
@@ -31,4 +36,13 @@ void test2(Supplier<Boolean> b) {
3136
sink(x, "B"); // $ flow=B
3237
sink(x, "C"); // $ flow=B
3338
}
39+
40+
void test3(Map m) {
41+
// Test implicit reads
42+
Object x = source("A");
43+
m.put("k", x);
44+
sink(m, "A"); // $ flow=A
45+
Object y = step(m, "A", "B");
46+
sink(y, "B"); // $ flow=A
47+
}
3448
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import java
2-
import semmle.code.java.dataflow.DataFlow
2+
import semmle.code.java.dataflow.TaintTracking
33
import TestUtilities.InlineExpectationsTest
44
import DataFlow
55

@@ -39,16 +39,16 @@ predicate step(Node n1, Node n2, string s1, string s2) {
3939

4040
predicate checkNode(Node n) { n.asExpr().(Argument).getCall().getCallee().hasName("check") }
4141

42-
class Conf extends Configuration {
42+
class Conf extends TaintTracking::Configuration {
4343
Conf() { this = "qltest:state" }
4444

4545
override predicate isSource(Node n, FlowState s) { src(n, s) }
4646

4747
override predicate isSink(Node n, FlowState s) { sink(n, s) }
4848

49-
override predicate isBarrier(Node n, FlowState s) { bar(n, s) }
49+
override predicate isSanitizer(Node n, FlowState s) { bar(n, s) }
5050

51-
override predicate isAdditionalFlowStep(Node n1, FlowState s1, Node n2, FlowState s2) {
51+
override predicate isAdditionalTaintStep(Node n1, FlowState s1, Node n2, FlowState s2) {
5252
step(n1, n2, s1, s2)
5353
}
5454

0 commit comments

Comments
 (0)