Skip to content

Commit 6792592

Browse files
committed
Shared: add late checks for stateful in/out barriers
1 parent 6d6cdf8 commit 6792592

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
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 |
52
#select
63
| A.java:9:16:9:19 | fsrc | A.java:13:10:13:10 | s | nobarrier, sinkbarrier |
74
| A.java:9:16:9:19 | fsrc | A.java:15:10:15:10 | s | nobarrier |

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ module MakeImpl<InputSig Lang> {
230230
)
231231
}
232232

233+
pragma[nomagic]
233234
private predicate inBarrier(NodeEx node, FlowState state) {
234235
exists(Node n |
235236
node.asNode() = n and
@@ -249,6 +250,7 @@ module MakeImpl<InputSig Lang> {
249250
)
250251
}
251252

253+
pragma[nomagic]
252254
private predicate outBarrier(NodeEx node, FlowState state) {
253255
exists(Node n |
254256
node.asNode() = n and
@@ -2518,6 +2520,7 @@ module MakeImpl<InputSig Lang> {
25182520
LocalCallContext cc
25192521
) {
25202522
not isUnreachableInCall1(node2, cc) and
2523+
not inBarrier(node2, state) and
25212524
(
25222525
localFlowEntry(node1, pragma[only_bind_into](state)) and
25232526
(
@@ -2532,18 +2535,21 @@ module MakeImpl<InputSig Lang> {
25322535
) and
25332536
node1 != node2 and
25342537
cc.relevantFor(node1.getEnclosingCallable()) and
2535-
not isUnreachableInCall1(node1, cc)
2538+
not isUnreachableInCall1(node1, cc) and
2539+
not outBarrier(node1, state)
25362540
or
25372541
exists(NodeEx mid |
25382542
localFlowStepPlus(node1, pragma[only_bind_into](state), mid, preservesValue, t, cc) and
25392543
localFlowStepNodeCand1(mid, node2) and
2544+
not outBarrier(mid, state) and
25402545
not mid instanceof FlowCheckNode and
25412546
Stage2::revFlow(node2, pragma[only_bind_into](state))
25422547
)
25432548
or
25442549
exists(NodeEx mid |
25452550
localFlowStepPlus(node1, state, mid, _, _, cc) and
25462551
additionalLocalFlowStepNodeCand2(mid, state, node2, state) and
2552+
not outBarrier(mid, state) and
25472553
not mid instanceof FlowCheckNode and
25482554
preservesValue = false and
25492555
t = node2.getDataFlowType()
@@ -3610,11 +3616,14 @@ module MakeImpl<InputSig Lang> {
36103616
}
36113617

36123618
override PathNodeImpl getASuccessorImpl() {
3613-
// an intermediate step to another intermediate node
3614-
result = this.getSuccMid()
3615-
or
3616-
// a final step to a sink
3617-
result = this.getSuccMid().projectToSink()
3619+
not outBarrier(node, state) and
3620+
(
3621+
// an intermediate step to another intermediate node
3622+
result = this.getSuccMid()
3623+
or
3624+
// a final step to a sink
3625+
result = this.getSuccMid().projectToSink()
3626+
)
36183627
}
36193628

36203629
override predicate isSource() {
@@ -3740,7 +3749,8 @@ module MakeImpl<InputSig Lang> {
37403749
exists(DataFlowType t0 |
37413750
pathStep0(mid, node, state, cc, sc, t0, ap) and
37423751
Stage5::revFlow(node, state, ap.getApprox()) and
3743-
strengthenType(node, t0, t)
3752+
strengthenType(node, t0, t) and
3753+
not inBarrier(node, state)
37443754
)
37453755
}
37463756

@@ -3838,11 +3848,15 @@ module MakeImpl<InputSig Lang> {
38383848
PathNodeMid mid, ReturnPosition pos, FlowState state, CallContext innercc,
38393849
AccessPathApprox apa
38403850
) {
3841-
pos = mid.getNodeEx().(RetNodeEx).getReturnPosition() and
3842-
state = mid.getState() and
3843-
innercc = mid.getCallContext() and
3844-
innercc instanceof CallContextNoCall and
3845-
apa = mid.getAp().getApprox()
3851+
exists(RetNodeEx retNode |
3852+
retNode = mid.getNodeEx() and
3853+
pos = retNode.getReturnPosition() and
3854+
state = mid.getState() and
3855+
not outBarrier(retNode, state) and
3856+
innercc = mid.getCallContext() and
3857+
innercc instanceof CallContextNoCall and
3858+
apa = mid.getAp().getApprox()
3859+
)
38463860
}
38473861

38483862
pragma[nomagic]
@@ -3874,7 +3888,8 @@ module MakeImpl<InputSig Lang> {
38743888
private predicate pathOutOfCallable(PathNodeMid mid, NodeEx out, FlowState state, CallContext cc) {
38753889
exists(ReturnKindExt kind, DataFlowCall call, AccessPathApprox apa |
38763890
pathOutOfCallable1(mid, call, kind, state, cc, apa) and
3877-
out = getAnOutNodeFlow(kind, call, apa)
3891+
out = getAnOutNodeFlow(kind, call, apa) and
3892+
not inBarrier(out, state)
38783893
)
38793894
}
38803895

@@ -3888,6 +3903,7 @@ module MakeImpl<InputSig Lang> {
38883903
) {
38893904
exists(ArgNodeEx arg, ArgumentPosition apos |
38903905
pathNode(mid, arg, state, cc, _, t, ap, _) and
3906+
not outBarrier(arg, state) and
38913907
arg.asNode().(ArgNode).argumentOf(call, apos) and
38923908
apa = ap.getApprox() and
38933909
parameterMatch(ppos, apos)
@@ -3930,6 +3946,7 @@ module MakeImpl<InputSig Lang> {
39303946
exists(ParameterPosition pos, DataFlowCallable callable, DataFlowType t, AccessPath ap |
39313947
pathIntoCallable0(mid, callable, pos, state, outercc, call, t, ap) and
39323948
p.isParameterOf(callable, pos) and
3949+
not inBarrier(p, state) and
39333950
(
39343951
sc = TSummaryCtxSome(p, state, t, ap)
39353952
or

0 commit comments

Comments
 (0)