Skip to content

Commit 6d6cdf8

Browse files
committed
Java: add a failing test for stateful in/out barriers
1 parent 6e86945 commit 6d6cdf8

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

java/ql/test/library-tests/dataflow/inoutbarriers/test.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
inconsistentFlow
2+
| A.java:9:16:9:19 | fsrc | A.java:15:10:15:10 | s | spurious state-flow in configuration sinkbarrier |
3+
| A.java:12:9:12:14 | src(...) | A.java:15:10:15:10 | s | spurious state-flow in configuration both |
4+
| A.java:12:9:12:14 | src(...) | A.java:15:10:15:10 | s | spurious state-flow in configuration sinkbarrier |
5+
#select
16
| A.java:9:16:9:19 | fsrc | A.java:13:10:13:10 | s | nobarrier, sinkbarrier |
27
| A.java:9:16:9:19 | fsrc | A.java:15:10:15:10 | s | nobarrier |
38
| A.java:10:10:10:13 | fsrc | A.java:10:10:10:13 | fsrc | both, nobarrier, sinkbarrier, srcbarrier |

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,46 @@ module Conf4 implements ConfigSig {
4646
predicate isBarrierOut(Node n) { sink0(n) }
4747
}
4848

49+
module StateConf1 implements StateConfigSig {
50+
class FlowState = Unit;
51+
52+
predicate isSource(Node n, FlowState state) { src0(n) and exists(state) }
53+
54+
predicate isSink(Node n, FlowState state) { sink0(n) and exists(state) }
55+
}
56+
57+
module StateConf2 implements StateConfigSig {
58+
class FlowState = Unit;
59+
60+
predicate isSource(Node n, FlowState state) { src0(n) and exists(state) }
61+
62+
predicate isSink(Node n, FlowState state) { sink0(n) and exists(state) }
63+
64+
predicate isBarrierIn(Node n, FlowState state) { isSource(n, state) }
65+
}
66+
67+
module StateConf3 implements StateConfigSig {
68+
class FlowState = Unit;
69+
70+
predicate isSource(Node n, FlowState state) { src0(n) and exists(state) }
71+
72+
predicate isSink(Node n, FlowState state) { sink0(n) and exists(state) }
73+
74+
predicate isBarrierOut(Node n, FlowState state) { isSink(n, state) }
75+
}
76+
77+
module StateConf4 implements StateConfigSig {
78+
class FlowState = Unit;
79+
80+
predicate isSource(Node n, FlowState state) { src0(n) and exists(state) }
81+
82+
predicate isSink(Node n, FlowState state) { sink0(n) and exists(state) }
83+
84+
predicate isBarrierIn(Node n, FlowState state) { isSource(n, state) }
85+
86+
predicate isBarrierOut(Node n, FlowState state) { isSink(n, state) }
87+
}
88+
4989
predicate flow(Node src, Node sink, string s) {
5090
Global<Conf1>::flow(src, sink) and s = "nobarrier"
5191
or
@@ -56,6 +96,26 @@ predicate flow(Node src, Node sink, string s) {
5696
Global<Conf4>::flow(src, sink) and s = "both"
5797
}
5898

99+
predicate stateFlow(Node src, Node sink, string s) {
100+
GlobalWithState<StateConf1>::flow(src, sink) and s = "nobarrier"
101+
or
102+
GlobalWithState<StateConf2>::flow(src, sink) and s = "srcbarrier"
103+
or
104+
GlobalWithState<StateConf3>::flow(src, sink) and s = "sinkbarrier"
105+
or
106+
GlobalWithState<StateConf4>::flow(src, sink) and s = "both"
107+
}
108+
109+
query predicate inconsistentFlow(Node src, Node sink, string message) {
110+
exists(string kind |
111+
(flow(src, sink, kind) and not stateFlow(src, sink, kind)) and
112+
message = "missing state-flow in configuration " + kind
113+
or
114+
(not flow(src, sink, kind) and stateFlow(src, sink, kind)) and
115+
message = "spurious state-flow in configuration " + kind
116+
)
117+
}
118+
59119
from Node src, Node sink, string s
60120
where flow(src, sink, _) and s = concat(any(string s0 | flow(src, sink, s0)), ", ")
61121
select src, sink, s

0 commit comments

Comments
 (0)