Skip to content

Commit faefa05

Browse files
authored
Merge pull request github#15507 from asgerf/shared/outbarrier-bugfix
Shared: fix a bug in stateful outbarriers
2 parents cbb9a64 + ee8e9a4 commit faefa05

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
class A {
22
static String fsrc = "";
3+
String fsink = "";
34

45
String src(String s) { return s; }
56

67
void sink(String s) { }
78

9+
static String flowThroughSink(String s) {
10+
A obj = new A();
11+
obj.fsink = s;
12+
return obj.fsink;
13+
}
14+
815
void foo() {
916
String s = fsrc;
1017
sink(fsrc);
@@ -13,5 +20,9 @@ void foo() {
1320
sink(s);
1421

1522
sink(s);
23+
24+
s = fsrc;
25+
s = flowThroughSink(s);
26+
sink(s);
1627
}
1728
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
inconsistentFlow
22
#select
3-
| A.java:9:16:9:19 | fsrc | A.java:13:10:13:10 | s | nobarrier, sinkbarrier |
4-
| A.java:9:16:9:19 | fsrc | A.java:15:10:15:10 | s | nobarrier |
5-
| A.java:10:10:10:13 | fsrc | A.java:10:10:10:13 | fsrc | both, nobarrier, sinkbarrier, srcbarrier |
6-
| A.java:12:9:12:14 | src(...) | A.java:13:10:13:10 | s | both, nobarrier, sinkbarrier, srcbarrier |
7-
| A.java:12:9:12:14 | src(...) | A.java:15:10:15:10 | s | nobarrier, srcbarrier |
3+
| A.java:16:16:16:19 | fsrc | A.java:20:10:20:10 | s | nobarrier, sinkbarrier |
4+
| A.java:16:16:16:19 | fsrc | A.java:22:10:22:10 | s | nobarrier |
5+
| A.java:17:10:17:13 | fsrc | A.java:17:10:17:13 | fsrc | both, nobarrier, sinkbarrier, srcbarrier |
6+
| A.java:19:9:19:14 | src(...) | A.java:20:10:20:10 | s | both, nobarrier, sinkbarrier, srcbarrier |
7+
| A.java:19:9:19:14 | src(...) | A.java:22:10:22:10 | s | nobarrier, srcbarrier |
8+
| A.java:24:9:24:12 | fsrc | A.java:11:17:11:17 | s | both, nobarrier, sinkbarrier, srcbarrier |
9+
| A.java:24:9:24:12 | fsrc | A.java:26:10:26:10 | s | nobarrier, srcbarrier |

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ predicate sink0(Node n) {
1212
sink.getMethod().hasName("sink") and
1313
sink.getAnArgument() = n.asExpr()
1414
)
15+
or
16+
exists(AssignExpr assign |
17+
assign.getDest().(FieldAccess).getField().hasName("fsink") and
18+
n.asExpr() = assign.getSource()
19+
)
1520
}
1621

1722
module Conf1 implements ConfigSig {

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,7 @@ module MakeImpl<InputSig Lang> {
26822682
) {
26832683
not isUnreachableInCall1(node2, cc) and
26842684
not inBarrier(node2, state) and
2685+
not outBarrier(node1, state) and
26852686
(
26862687
localFlowEntry(node1, pragma[only_bind_into](state)) and
26872688
(
@@ -3761,6 +3762,9 @@ module MakeImpl<InputSig Lang> {
37613762

37623763
override NodeEx getNodeEx() { result = node }
37633764

3765+
pragma[inline]
3766+
final NodeEx getNodeExOutgoing() { result = node and not outBarrier(node, state) }
3767+
37643768
override FlowState getState() { result = state }
37653769

37663770
CallContext getCallContext() { result = cc }
@@ -3777,14 +3781,11 @@ module MakeImpl<InputSig Lang> {
37773781
}
37783782

37793783
override PathNodeImpl getASuccessorImpl() {
3780-
not outBarrier(node, state) and
3781-
(
3782-
// an intermediate step to another intermediate node
3783-
result = this.getSuccMid()
3784-
or
3785-
// a final step to a sink
3786-
result = this.getSuccMid().projectToSink()
3787-
)
3784+
// an intermediate step to another intermediate node
3785+
result = this.getSuccMid()
3786+
or
3787+
// a final step to a sink
3788+
result = this.getSuccMid().projectToSink()
37883789
}
37893790

37903791
override predicate isSource() {
@@ -3935,22 +3936,22 @@ module MakeImpl<InputSig Lang> {
39353936
ap instanceof AccessPathNil
39363937
)
39373938
or
3938-
jumpStepEx(mid.getNodeEx(), node) and
3939+
jumpStepEx(mid.getNodeExOutgoing(), node) and
39393940
state = mid.getState() and
39403941
cc instanceof CallContextAny and
39413942
sc instanceof SummaryCtxNone and
39423943
t = mid.getType() and
39433944
ap = mid.getAp()
39443945
or
3945-
additionalJumpStep(mid.getNodeEx(), node) and
3946+
additionalJumpStep(mid.getNodeExOutgoing(), node) and
39463947
state = mid.getState() and
39473948
cc instanceof CallContextAny and
39483949
sc instanceof SummaryCtxNone and
39493950
mid.getAp() instanceof AccessPathNil and
39503951
t = node.getDataFlowType() and
39513952
ap = TAccessPathNil()
39523953
or
3953-
additionalJumpStateStep(mid.getNodeEx(), mid.getState(), node, state) and
3954+
additionalJumpStateStep(mid.getNodeExOutgoing(), mid.getState(), node, state) and
39543955
cc instanceof CallContextAny and
39553956
sc instanceof SummaryCtxNone and
39563957
mid.getAp() instanceof AccessPathNil and
@@ -3985,7 +3986,7 @@ module MakeImpl<InputSig Lang> {
39853986
) {
39863987
ap0 = mid.getAp() and
39873988
c = ap0.getHead() and
3988-
Stage5::readStepCand(mid.getNodeEx(), c, node) and
3989+
Stage5::readStepCand(mid.getNodeExOutgoing(), c, node) and
39893990
state = mid.getState() and
39903991
cc = mid.getCallContext()
39913992
}
@@ -3998,7 +3999,7 @@ module MakeImpl<InputSig Lang> {
39983999
exists(DataFlowType contentType |
39994000
t0 = mid.getType() and
40004001
ap0 = mid.getAp() and
4001-
Stage5::storeStepCand(mid.getNodeEx(), _, c, node, contentType, t) and
4002+
Stage5::storeStepCand(mid.getNodeExOutgoing(), _, c, node, contentType, t) and
40024003
state = mid.getState() and
40034004
cc = mid.getCallContext() and
40044005
compatibleTypes(t0, contentType)
@@ -4016,7 +4017,8 @@ module MakeImpl<InputSig Lang> {
40164017
not outBarrier(retNode, state) and
40174018
innercc = mid.getCallContext() and
40184019
innercc instanceof CallContextNoCall and
4019-
apa = mid.getAp().getApprox()
4020+
apa = mid.getAp().getApprox() and
4021+
not outBarrier(retNode, state)
40204022
)
40214023
}
40224024

@@ -4137,7 +4139,8 @@ module MakeImpl<InputSig Lang> {
41374139
pathNode(_, ret, state, cc, sc, t, ap, _) and
41384140
kind = ret.getKind() and
41394141
apa = ap.getApprox() and
4140-
parameterFlowThroughAllowed(sc.getParamNode(), kind)
4142+
parameterFlowThroughAllowed(sc.getParamNode(), kind) and
4143+
not outBarrier(ret, state)
41414144
)
41424145
}
41434146

0 commit comments

Comments
 (0)