Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5a2c26

Browse files
committed
Dataflow: Refactor forward store step relation.
1 parent b6f1ab6 commit c5a2c26

1 file changed

Lines changed: 39 additions & 41 deletions

File tree

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl.qll

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,17 @@ private module Stage2 {
11421142
)
11431143
}
11441144

1145+
pragma[nomagic]
1146+
predicate storeStepCand(
1147+
Node node1, Ap ap1, TypedContent tc, Node node2, DataFlowType contentType, Configuration config
1148+
) {
1149+
exists(Ap ap2, Content c |
1150+
store(node1, tc, node2, contentType) and
1151+
revFlowStore(ap2, c, ap1, node1, tc, node2, _, _, config) and
1152+
revFlowConsCand(ap2, c, ap1, config)
1153+
)
1154+
}
1155+
11451156
predicate revFlow(Node node, Configuration config) { revFlow(node, _, _, _, config) }
11461157
/* End: Stage 2 logic. */
11471158
}
@@ -1292,16 +1303,6 @@ private predicate readCand2(Node node1, Content c, Node node2, Configuration con
12921303
Stage2::revFlowIsReadAndStored(c, unbind(config))
12931304
}
12941305

1295-
pragma[nomagic]
1296-
private predicate storeCand2(
1297-
Node node1, TypedContent tc, Node node2, DataFlowType contentType, Configuration config
1298-
) {
1299-
store(node1, tc, node2, contentType) and
1300-
Stage2::revFlow(node1, config) and
1301-
Stage2::revFlow(node2, _, _, true, unbind(config)) and
1302-
Stage2::revFlowIsReadAndStored(tc.getContent(), unbind(config))
1303-
}
1304-
13051306
private module Stage3 {
13061307
class ApApprox = Stage2::Ap;
13071308

@@ -1451,7 +1452,7 @@ private module Stage3 {
14511452
) {
14521453
exists(DataFlowType contentType |
14531454
fwdFlow(node1, cc, argAp, ap1, config) and
1454-
storeCand2(node1, tc, node2, contentType, config) and
1455+
Stage2::storeStepCand(node1, getApprox(ap1), tc, node2, contentType, config) and
14551456
// We need to typecheck stores here, since reverse flow through a getter
14561457
// might have a different type here compared to inside the getter.
14571458
compatibleTypes(ap1.getType(), contentType)
@@ -1691,6 +1692,17 @@ private module Stage3 {
16911692
)
16921693
}
16931694

1695+
pragma[nomagic]
1696+
predicate storeStepCand(
1697+
Node node1, Ap ap1, TypedContent tc, Node node2, DataFlowType contentType, Configuration config
1698+
) {
1699+
exists(Ap ap2, Content c |
1700+
store(node1, tc, node2, contentType) and
1701+
revFlowStore(ap2, c, ap1, node1, tc, node2, _, _, config) and
1702+
revFlowConsCand(ap2, c, ap1, config)
1703+
)
1704+
}
1705+
16941706
predicate readStepCand(Node node1, Content c, Node node2, Configuration config) {
16951707
exists(Ap ap |
16961708
revFlow(node2, _, _, ap, config) and
@@ -2060,8 +2072,10 @@ private module Stage4 {
20602072
private predicate fwdFlowStore(
20612073
Node node1, Ap ap1, TypedContent tc, Node node2, Cc cc, ApOption argAp, Configuration config
20622074
) {
2063-
fwdFlow(node1, cc, argAp, ap1, config) and
2064-
fwdFlowStore0(node1, tc, node2, ap1.getFront(), config)
2075+
exists(DataFlowType contentType |
2076+
fwdFlow(node1, cc, argAp, ap1, config) and
2077+
Stage3::storeStepCand(node1, getApprox(ap1), tc, node2, contentType, config)
2078+
)
20652079
}
20662080

20672081
pragma[nomagic]
@@ -2073,27 +2087,6 @@ private module Stage4 {
20732087
)
20742088
}
20752089

2076-
pragma[nomagic]
2077-
private predicate storeCand(
2078-
Node mid, TypedContent tc, Node node, AccessPathFront apf0, AccessPathFront apf,
2079-
Configuration config
2080-
) {
2081-
storeCand2(mid, tc, node, _, config) and
2082-
flowCand(mid, apf0, config) and
2083-
apf.headUsesContent(tc)
2084-
}
2085-
2086-
pragma[noinline]
2087-
private predicate fwdFlowStore0(
2088-
Node mid, TypedContent tc, Node node, AccessPathFront apf0, Configuration config
2089-
) {
2090-
exists(AccessPathFront apf |
2091-
storeCand(mid, tc, node, apf0, apf, config) and
2092-
stage3consCand(tc, apf0, config) and
2093-
flowCand(node, apf, unbind(config))
2094-
)
2095-
}
2096-
20972090
pragma[nomagic]
20982091
private predicate fwdFlowRead(
20992092
Ap ap, Content c, Node node1, Node node2, Cc cc, ApOption argAp, Configuration config
@@ -2316,6 +2309,17 @@ private module Stage4 {
23162309
)
23172310
}
23182311

2312+
pragma[nomagic]
2313+
predicate storeStepCand(
2314+
Node node1, Ap ap1, TypedContent tc, Node node2, DataFlowType contentType, Configuration config
2315+
) {
2316+
exists(Ap ap2, Content c |
2317+
store(node1, tc, node2, contentType) and
2318+
revFlowStore(ap2, c, ap1, node1, tc, node2, _, _, config) and
2319+
revFlowConsCand(ap2, c, ap1, config)
2320+
)
2321+
}
2322+
23192323
predicate revFlow(Node n, Configuration config) { revFlow(n, _, _, _, config) }
23202324
/* End: Stage 4 logic. */
23212325
}
@@ -2929,18 +2933,12 @@ private predicate pathReadStep(
29292933
cc = mid.getCallContext()
29302934
}
29312935

2932-
pragma[nomagic]
2933-
private predicate storeCand(Node node1, TypedContent tc, Node node2, Configuration config) {
2934-
storeCand2(node1, tc, node2, _, config) and
2935-
Stage4::revFlow(node2, config)
2936-
}
2937-
29382936
pragma[nomagic]
29392937
private predicate pathStoreStep(
29402938
PathNodeMid mid, Node node, AccessPath ap0, TypedContent tc, CallContext cc
29412939
) {
29422940
ap0 = mid.getAp() and
2943-
storeCand(mid.getNode(), tc, node, mid.getConfiguration()) and
2941+
Stage4::storeStepCand(mid.getNode(), _, tc, node, _, mid.getConfiguration()) and
29442942
cc = mid.getCallContext()
29452943
}
29462944

0 commit comments

Comments
 (0)