Skip to content

Commit cda26ba

Browse files
committed
Dataflow: Split TypedContent in store relation.
1 parent 246d904 commit cda26ba

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

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

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,10 @@ module Impl<FullStateConfigSig Config> {
390390
private predicate hasReadStep(Content c) { read(_, c, _) }
391391

392392
pragma[nomagic]
393-
private predicate storeEx(NodeEx node1, TypedContent tc, NodeEx node2, DataFlowType contentType) {
394-
store(pragma[only_bind_into](node1.asNode()), tc, pragma[only_bind_into](node2.asNode()),
395-
contentType) and
396-
hasReadStep(tc.getContent()) and
393+
private predicate storeEx(NodeEx node1, TypedContent tc, Content c, NodeEx node2, DataFlowType contentType, DataFlowType containerType) {
394+
store(pragma[only_bind_into](node1.asNode()), tc, c, pragma[only_bind_into](node2.asNode()),
395+
contentType, containerType) and
396+
hasReadStep(c) and
397397
stepFilter(node1, node2)
398398
}
399399

@@ -478,7 +478,7 @@ module Impl<FullStateConfigSig Config> {
478478
exists(NodeEx mid |
479479
useFieldFlow() and
480480
fwdFlow(mid, cc) and
481-
storeEx(mid, _, node, _)
481+
storeEx(mid, _, _, node, _, _)
482482
)
483483
or
484484
// read
@@ -570,12 +570,11 @@ module Impl<FullStateConfigSig Config> {
570570
pragma[assume_small_delta]
571571
pragma[nomagic]
572572
private predicate fwdFlowConsCand(Content c) {
573-
exists(NodeEx mid, NodeEx node, TypedContent tc |
573+
exists(NodeEx mid, NodeEx node |
574574
not fullBarrier(node) and
575575
useFieldFlow() and
576576
fwdFlow(mid, _) and
577-
storeEx(mid, tc, node, _) and
578-
c = tc.getContent()
577+
storeEx(mid, _, c, node, _, _)
579578
)
580579
}
581580

@@ -709,11 +708,10 @@ module Impl<FullStateConfigSig Config> {
709708

710709
pragma[nomagic]
711710
private predicate revFlowStore(Content c, NodeEx node, boolean toReturn) {
712-
exists(NodeEx mid, TypedContent tc |
711+
exists(NodeEx mid |
713712
revFlow(mid, toReturn) and
714713
fwdFlowConsCand(c) and
715-
storeEx(node, tc, mid, _) and
716-
c = tc.getContent()
714+
storeEx(node, _, c, mid, _, _)
717715
)
718716
}
719717

@@ -803,15 +801,12 @@ module Impl<FullStateConfigSig Config> {
803801

804802
pragma[nomagic]
805803
predicate storeStepCand(
806-
NodeEx node1, Ap ap1, TypedContent tc, NodeEx node2, DataFlowType contentType
804+
NodeEx node1, Ap ap1, TypedContent tc, Content c, NodeEx node2, DataFlowType contentType, DataFlowType containerType
807805
) {
808-
exists(Content c |
809-
revFlowIsReadAndStored(c) and
810-
revFlow(node2) and
811-
storeEx(node1, tc, node2, contentType) and
812-
c = tc.getContent() and
813-
exists(ap1)
814-
)
806+
revFlowIsReadAndStored(c) and
807+
revFlow(node2) and
808+
storeEx(node1, tc, c, node2, contentType, containerType) and
809+
exists(ap1)
815810
}
816811

817812
pragma[nomagic]
@@ -1053,7 +1048,7 @@ module Impl<FullStateConfigSig Config> {
10531048
predicate returnMayFlowThrough(RetNodeEx ret, Ap argAp, Ap ap, ReturnKindExt kind);
10541049

10551050
predicate storeStepCand(
1056-
NodeEx node1, Ap ap1, TypedContent tc, NodeEx node2, DataFlowType contentType
1051+
NodeEx node1, Ap ap1, TypedContent tc, Content c, NodeEx node2, DataFlowType contentType, DataFlowType containerType
10571052
);
10581053

10591054
predicate readStepCand(NodeEx n1, Content c, NodeEx n2);
@@ -1306,7 +1301,7 @@ module Impl<FullStateConfigSig Config> {
13061301
) {
13071302
exists(DataFlowType contentType, ApApprox apa1 |
13081303
fwdFlow(node1, state, cc, summaryCtx, argAp, ap1, apa1) and
1309-
PrevStage::storeStepCand(node1, apa1, tc, node2, contentType) and
1304+
PrevStage::storeStepCand(node1, apa1, tc, _, node2, contentType, _) and
13101305
typecheckStore(ap1, contentType)
13111306
)
13121307
}
@@ -1659,10 +1654,10 @@ module Impl<FullStateConfigSig Config> {
16591654

16601655
pragma[nomagic]
16611656
predicate storeStepCand(
1662-
NodeEx node1, Ap ap1, TypedContent tc, NodeEx node2, DataFlowType contentType
1657+
NodeEx node1, Ap ap1, TypedContent tc, Content c, NodeEx node2, DataFlowType contentType, DataFlowType containerType
16631658
) {
1664-
exists(Ap ap2, Content c |
1665-
PrevStage::storeStepCand(node1, _, tc, node2, contentType) and
1659+
exists(Ap ap2 |
1660+
PrevStage::storeStepCand(node1, _, tc, c, node2, contentType, containerType) and
16661661
revFlowStore(ap2, c, ap1, node1, _, tc, node2, _, _) and
16671662
revFlowConsCand(ap2, c, ap1)
16681663
)
@@ -1688,7 +1683,7 @@ module Impl<FullStateConfigSig Config> {
16881683

16891684
private predicate fwdConsCand(TypedContent tc, Ap ap) { storeStepFwd(_, ap, tc, _, _) }
16901685

1691-
private predicate revConsCand(TypedContent tc, Ap ap) { storeStepCand(_, ap, tc, _, _) }
1686+
private predicate revConsCand(TypedContent tc, Ap ap) { storeStepCand(_, ap, tc, _, _, _, _) }
16921687

16931688
private predicate validAp(Ap ap) {
16941689
revFlow(_, _, _, _, ap) and ap instanceof ApNil
@@ -2003,7 +1998,7 @@ module Impl<FullStateConfigSig Config> {
20031998
or
20041999
node.asNode() instanceof OutNodeExt
20052000
or
2006-
Stage2::storeStepCand(_, _, _, node, _)
2001+
Stage2::storeStepCand(_, _, _, _, node, _, _)
20072002
or
20082003
Stage2::readStepCand(_, _, node)
20092004
or
@@ -2026,7 +2021,7 @@ module Impl<FullStateConfigSig Config> {
20262021
additionalJumpStep(node, next) or
20272022
flowIntoCallNodeCand2(_, node, next, _) or
20282023
flowOutOfCallNodeCand2(_, node, _, next, _) or
2029-
Stage2::storeStepCand(node, _, _, next, _) or
2024+
Stage2::storeStepCand(node, _, _, _, next, _, _) or
20302025
Stage2::readStepCand(node, _, next)
20312026
)
20322027
or
@@ -3386,7 +3381,7 @@ module Impl<FullStateConfigSig Config> {
33863381
PathNodeMid mid, NodeEx node, FlowState state, AccessPath ap0, TypedContent tc, CallContext cc
33873382
) {
33883383
ap0 = mid.getAp() and
3389-
Stage5::storeStepCand(mid.getNodeEx(), _, tc, node, _) and
3384+
Stage5::storeStepCand(mid.getNodeEx(), _, tc, _, node, _, _) and
33903385
state = mid.getState() and
33913386
cc = mid.getCallContext()
33923387
}
@@ -3593,7 +3588,7 @@ module Impl<FullStateConfigSig Config> {
35933588
result.isHidden() and
35943589
exists(NodeEx n1, NodeEx n2 | n1 = n.getNodeEx() and n2 = result.getNodeEx() |
35953590
localFlowBigStep(n1, _, n2, _, _, _, _) or
3596-
storeEx(n1, _, n2, _) or
3591+
storeEx(n1, _, _, n2, _, _) or
35973592
readSetEx(n1, _, n2)
35983593
)
35993594
}
@@ -4271,7 +4266,7 @@ module Impl<FullStateConfigSig Config> {
42714266
exists(NodeEx midNode, DataFlowType contentType |
42724267
midNode = mid.getNodeEx() and
42734268
ap1 = mid.getAp() and
4274-
storeEx(midNode, tc, node, contentType) and
4269+
storeEx(midNode, tc, _, node, contentType, _) and
42754270
ap2.getHead() = tc and
42764271
ap2.len() = unbindInt(ap1.len() + 1) and
42774272
compatibleTypes(ap1.getType(), contentType)
@@ -4522,12 +4517,11 @@ module Impl<FullStateConfigSig Config> {
45224517
private predicate revPartialPathStoreStep(
45234518
PartialPathNodeRev mid, RevPartialAccessPath ap, Content c, NodeEx node
45244519
) {
4525-
exists(NodeEx midNode, TypedContent tc |
4520+
exists(NodeEx midNode |
45264521
midNode = mid.getNodeEx() and
45274522
ap = mid.getAp() and
4528-
storeEx(node, tc, midNode, _) and
4529-
ap.getHead() = c and
4530-
tc.getContent() = c
4523+
storeEx(node, _, c, midNode, _, _) and
4524+
ap.getHead() = c
45314525
)
45324526
}
45334527

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,10 @@ private module Cached {
831831
* been stored into, in order to handle cases like `x.f1.f2 = y`.
832832
*/
833833
cached
834-
predicate store(Node node1, TypedContent tc, Node node2, DataFlowType contentType) {
835-
store(node1, tc.getContent(), node2, contentType, tc.getContainerType())
834+
predicate store(Node node1, TypedContent tc, Content c, Node node2, DataFlowType contentType, DataFlowType containerType) {
835+
tc.getContent() = c and
836+
tc.getContainerType() = containerType and
837+
store(node1, c, node2, contentType, containerType)
836838
}
837839

838840
/**

0 commit comments

Comments
 (0)