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

Skip to content

Commit 3e18e02

Browse files
committed
Dataflow: Refactor step predicate in fwdFlowRead.
1 parent c5a2c26 commit 3e18e02

1 file changed

Lines changed: 23 additions & 49 deletions

File tree

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

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,29 +1073,6 @@ private module Stage2 {
10731073
)
10741074
}
10751075

1076-
/**
1077-
* Holds if `c` is the target of a store in the flow covered by `revFlow`.
1078-
*/
1079-
pragma[nomagic]
1080-
private predicate revFlowIsStored(Content c, Ap ap, Configuration conf) {
1081-
exists(Node node |
1082-
revFlowStore(_, c, ap, node, _, _, _, _, conf) and
1083-
revFlow(node, _, _, ap, conf)
1084-
)
1085-
}
1086-
1087-
/**
1088-
* Holds if `c` is the target of both a store and a read in the path graph
1089-
* covered by `revFlow`.
1090-
*/
1091-
pragma[noinline]
1092-
predicate revFlowIsReadAndStored(Content c, Configuration conf) {
1093-
exists(Ap ap |
1094-
revFlowIsStored(c, ap, conf) and
1095-
revFlowConsCand(_, c, ap, conf)
1096-
)
1097-
}
1098-
10991076
pragma[nomagic]
11001077
private predicate revFlowOut(
11011078
DataFlowCall call, ReturnNodeExt ret, boolean toReturn, ApOption returnAp, Ap ap,
@@ -1153,6 +1130,14 @@ private module Stage2 {
11531130
)
11541131
}
11551132

1133+
predicate readStepCand(Node node1, Content c, Node node2, Configuration config) {
1134+
exists(Ap ap1, Ap ap2 |
1135+
revFlow(node2, _, _, ap2, config) and
1136+
readStepFwd(node1, ap1, c, node2, ap2, config) and
1137+
revFlowStore(ap1, c, /*unbind*/ ap2, _, _, _, _, _, unbind(config))
1138+
)
1139+
}
1140+
11561141
predicate revFlow(Node node, Configuration config) { revFlow(node, _, _, _, config) }
11571142
/* End: Stage 2 logic. */
11581143
}
@@ -1295,14 +1280,6 @@ private module LocalFlowBigStep {
12951280

12961281
private import LocalFlowBigStep
12971282

1298-
pragma[nomagic]
1299-
private predicate readCand2(Node node1, Content c, Node node2, Configuration config) {
1300-
read(node1, c, node2, config) and
1301-
Stage2::revFlow(node1, _, _, true, unbind(config)) and
1302-
Stage2::revFlow(node2, config) and
1303-
Stage2::revFlowIsReadAndStored(c, unbind(config))
1304-
}
1305-
13061283
private module Stage3 {
13071284
class ApApprox = Stage2::Ap;
13081285

@@ -1473,7 +1450,7 @@ private module Stage3 {
14731450
Ap ap, Content c, Node node1, Node node2, Cc cc, ApOption argAp, Configuration config
14741451
) {
14751452
fwdFlow(node1, cc, argAp, ap, config) and
1476-
readCand2(node1, c, node2, config) and
1453+
Stage2::readStepCand(node1, c, node2, config) and
14771454
getHeadContent(ap) = c
14781455
}
14791456

@@ -1621,13 +1598,6 @@ private module Stage3 {
16211598
if fwdFlow(node, true, _, ap, config) then returnAp = apSome(ap) else returnAp = apNone()
16221599
}
16231600

1624-
// TODO: remove
1625-
pragma[nomagic]
1626-
predicate readCandFwd(Node node1, TypedContent tc, Ap ap, Node node2, Configuration config) {
1627-
fwdFlowRead(ap, _, node1, node2, _, _, config) and
1628-
ap.headUsesContent(tc)
1629-
}
1630-
16311601
pragma[nomagic]
16321602
private predicate revFlowStore(
16331603
Ap ap0, Content c, Ap ap, Node node, TypedContent tc, Node mid, boolean toReturn,
@@ -1704,9 +1674,10 @@ private module Stage3 {
17041674
}
17051675

17061676
predicate readStepCand(Node node1, Content c, Node node2, Configuration config) {
1707-
exists(Ap ap |
1708-
revFlow(node2, _, _, ap, config) and
1709-
readStepFwd(node1, _, c, node2, ap, config)
1677+
exists(Ap ap1, Ap ap2 |
1678+
revFlow(node2, _, _, ap2, config) and
1679+
readStepFwd(node1, ap1, c, node2, ap2, config) and
1680+
revFlowStore(ap1, c, /*unbind*/ ap2, _, _, _, _, _, unbind(config))
17101681
)
17111682
}
17121683
/* End: Stage 3 logic. */
@@ -2320,6 +2291,14 @@ private module Stage4 {
23202291
)
23212292
}
23222293

2294+
predicate readStepCand(Node node1, Content c, Node node2, Configuration config) {
2295+
exists(Ap ap1, Ap ap2 |
2296+
revFlow(node2, _, _, ap2, config) and
2297+
readStepFwd(node1, ap1, c, node2, ap2, config) and
2298+
revFlowStore(ap1, c, /*unbind*/ ap2, _, _, _, _, _, unbind(config))
2299+
)
2300+
}
2301+
23232302
predicate revFlow(Node n, Configuration config) { revFlow(n, _, _, _, config) }
23242303
/* End: Stage 4 logic. */
23252304
}
@@ -2918,18 +2897,13 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
29182897
pathThroughCallable(mid, node, cc, ap) and sc = mid.getSummaryCtx()
29192898
}
29202899

2921-
pragma[nomagic]
2922-
private predicate readCand(Node node1, TypedContent tc, Node node2, Configuration config) {
2923-
Stage3::readCandFwd(node1, tc, _, node2, config) and
2924-
Stage4::revFlow(node2, config)
2925-
}
2926-
29272900
pragma[nomagic]
29282901
private predicate pathReadStep(
29292902
PathNodeMid mid, Node node, AccessPath ap0, TypedContent tc, CallContext cc
29302903
) {
29312904
ap0 = mid.getAp() and
2932-
readCand(mid.getNode(), tc, node, mid.getConfiguration()) and
2905+
tc = ap0.getHead() and
2906+
Stage4::readStepCand(mid.getNode(), tc.getContent(), node, mid.getConfiguration()) and
29332907
cc = mid.getCallContext()
29342908
}
29352909

0 commit comments

Comments
 (0)