Skip to content

Commit 927d3e2

Browse files
committed
wip2
1 parent 5717541 commit 927d3e2

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

shared/dataflow/codeql/dataflow/DataFlow.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ signature module InputSig<LocationSig Location> {
276276
*/
277277
predicate isUnreachableInCall(NodeRegion nr, DataFlowCall call);
278278

279+
/** Gets the access path limit. A maximum limit of 5 is allowed. */
279280
default int accessPathLimit() { result = 5 }
280281

281282
/**
@@ -412,7 +413,7 @@ module Configs<LocationSig Location, InputSig<Location> Lang> {
412413
*/
413414
default int fieldFlowBranchLimit() { result = 2 }
414415

415-
/** Gets the access path limit. */
416+
/** Gets the access path limit. A maximum limit of 5 is allowed. */
416417
default int accessPathLimit() { result = Lang::accessPathLimit() }
417418

418419
/**
@@ -534,7 +535,7 @@ module Configs<LocationSig Location, InputSig<Location> Lang> {
534535
*/
535536
default int fieldFlowBranchLimit() { result = 2 }
536537

537-
/** Gets the access path limit. */
538+
/** Gets the access path limit. A maximum limit of 5 is allowed. */
538539
default int accessPathLimit() { result = Lang::accessPathLimit() }
539540

540541
/**

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

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
9494
*/
9595
int fieldFlowBranchLimit();
9696

97-
/** Gets the access path limit. */
97+
/** Gets the access path limit. A maximum limit of 5 is allowed. */
9898
int accessPathLimit();
9999

100100
/**
@@ -2562,10 +2562,15 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25622562
/** Input from previous iteration. */
25632563
private signature predicate storeReachesReadSig(NodeEx node1, NodeEx node2);
25642564

2565+
private signature int iterationSig();
2566+
25652567
private module StoreReachesRead<
25662568
storeReachesReadSig/2 storeReachesReadPrevDelta,
2567-
storeReachesReadSig/2 storeReachesReadPrevPrev>
2569+
storeReachesReadSig/2 storeReachesReadPrevPrev, iterationSig/0 iteration>
25682570
{
2571+
private predicate enabled() { Config::accessPathLimit() > iteration() }
2572+
2573+
// private predicate enabled() { any() }
25692574
pragma[nomagic]
25702575
private predicate step(NodeEx node1, NodeEx node2, boolean usesPrevDelta) {
25712576
valueStep(node1, node2) and
@@ -2591,7 +2596,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25912596
}
25922597

25932598
private predicate stepNodeOrContent(ContentOrNodeContent n1, ContentOrNodeContent n2) {
2594-
step(n1.asNodeEx(), n2.asNodeEx(), _)
2599+
exists(boolean usesPrevDelta | step(n1.asNodeEx(), n2.asNodeEx(), usesPrevDelta) |
2600+
usesPrevDelta = false or enabled()
2601+
)
25952602
or
25962603
storeStepCand0(_, _, n1.asContent(), n2.asNodeEx(), _, _)
25972604
or
@@ -2618,23 +2625,33 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26182625
}
26192626

26202627
private predicate isStoreTarget(NodeAndBoolean node) {
2628+
enabled() and
26212629
exists(Content c |
26222630
contentIsReadAndStored(c) and
26232631
storeStepCand0(_, _, c, node.getNodeEx(), _, _) and
26242632
node.getBoolean() = false
26252633
)
26262634
}
26272635

2636+
private boolean mustUsePrevDelta() {
2637+
exists(int iteration |
2638+
iteration = iteration() and
2639+
if iteration > 0 then result = true else result = false
2640+
)
2641+
}
2642+
26282643
private predicate isReadSource(NodeAndBoolean node) {
2644+
enabled() and
26292645
exists(Content c |
26302646
contentIsReadAndStored(c) and
26312647
readStepCand0(node.getNodeEx(), c, _) and
2632-
node.getBoolean() = true
2648+
node.getBoolean() = mustUsePrevDelta()
26332649
)
26342650
}
26352651

26362652
pragma[nomagic]
26372653
private predicate step0(NodeAndBoolean node1, NodeAndBoolean node2) {
2654+
enabled() and
26382655
exists(boolean usesPrevDelta |
26392656
step(node1.getNodeEx(), node2.getNodeEx(), usesPrevDelta)
26402657
|
@@ -2649,6 +2666,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26492666
private predicate storeStepCandIsReadAndStored(
26502667
NodeEx node1, Content c, NodeAndBoolean node2
26512668
) {
2669+
enabled() and
26522670
contentIsReadAndStored(c) and
26532671
storeStepCand0(node1, _, c, node2.getNodeEx(), _, _) and
26542672
node2.getBoolean() = false
@@ -2658,9 +2676,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26582676
private predicate readStepCandIsReadAndStored(
26592677
NodeAndBoolean node1, Content c, NodeEx node2
26602678
) {
2679+
enabled() and
26612680
contentIsReadAndStored(c) and
26622681
readStepCand0(node1.getNodeEx(), c, node2) and
2663-
node1.getBoolean() = true
2682+
node1.getBoolean() = mustUsePrevDelta()
26642683
}
26652684

26662685
pragma[nomagic]
@@ -2680,12 +2699,14 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26802699
}
26812700
}
26822701

2683-
private predicate storeReachesReadPrevDelta0(NodeEx node1, NodeEx node2) { node1 = node2 }
2702+
private predicate storeReachesReadPrevDelta0(NodeEx node1, NodeEx node2) { none() }
26842703

26852704
private predicate storeReachesReadPrevPrev0(NodeEx node1, NodeEx node2) { none() }
26862705

2706+
private int iteration0() { result = 0 }
2707+
26872708
private module StoreReachesRead1 =
2688-
StoreReachesRead<storeReachesReadPrevDelta0/2, storeReachesReadPrevPrev0/2>;
2709+
StoreReachesRead<storeReachesReadPrevDelta0/2, storeReachesReadPrevPrev0/2, iteration0/0>;
26892710

26902711
private predicate storeReachesReadPrevDelta1(NodeEx storeSource, NodeEx readTarget) {
26912712
StoreReachesRead1::storeReachesReadDelta(storeSource, readTarget)
@@ -2701,30 +2722,45 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
27012722
none()
27022723
}
27032724

2725+
private int iteration1() { result = 1 }
2726+
27042727
private module StoreReachesRead2 =
2705-
StoreReachesRead<storeReachesReadPrevDelta1/2, storeReachesReadPrevPrev1/2>;
2728+
StoreReachesRead<storeReachesReadPrevDelta1/2, storeReachesReadPrevPrev1/2, iteration1/0>;
27062729

27072730
private predicate storeReachesReadPrevDelta2 = StoreReachesRead2::storeReachesReadDelta/2;
27082731

27092732
private predicate storeReachesReadPrevPrev2 = StoreReachesRead2::storeReachesReadPrev/2;
27102733

2734+
private int iteration2() { result = 2 }
2735+
27112736
private module StoreReachesRead3 =
2712-
StoreReachesRead<storeReachesReadPrevDelta2/2, storeReachesReadPrevPrev2/2>;
2737+
StoreReachesRead<storeReachesReadPrevDelta2/2, storeReachesReadPrevPrev2/2, iteration2/0>;
27132738

27142739
private predicate storeReachesReadPrevDelta3 = StoreReachesRead3::storeReachesReadDelta/2;
27152740

27162741
private predicate storeReachesReadPrevPrev3 = StoreReachesRead3::storeReachesReadPrev/2;
27172742

2743+
private int iteration3() { result = 3 }
2744+
27182745
private module StoreReachesRead4 =
2719-
StoreReachesRead<storeReachesReadPrevDelta3/2, storeReachesReadPrevPrev3/2>;
2746+
StoreReachesRead<storeReachesReadPrevDelta3/2, storeReachesReadPrevPrev3/2, iteration3/0>;
2747+
2748+
private predicate storeReachesReadPrevDelta4 = StoreReachesRead4::storeReachesReadDelta/2;
2749+
2750+
private predicate storeReachesReadPrevPrev4 = StoreReachesRead4::storeReachesReadPrev/2;
2751+
2752+
private int iteration4() { result = 4 }
2753+
2754+
private module StoreReachesRead5 =
2755+
StoreReachesRead<storeReachesReadPrevDelta4/2, storeReachesReadPrevPrev4/2, iteration4/0>;
27202756

27212757
predicate storeReachesRead(NodeEx storeSource, NodeEx readTarget) {
2722-
StoreReachesRead4::storeReachesReadDelta(storeSource, readTarget)
2758+
StoreReachesRead5::storeReachesReadDelta(storeSource, readTarget)
27232759
or
2724-
StoreReachesRead4::storeReachesReadPrev(storeSource, readTarget)
2760+
StoreReachesRead5::storeReachesReadPrev(storeSource, readTarget)
27252761
}
27262762

2727-
predicate contentIsReadAndStored = StoreReachesRead4::contentIsReadAndStored/1;
2763+
predicate contentIsReadAndStored = StoreReachesRead5::contentIsReadAndStored/1;
27282764
}
27292765

27302766
predicate storeReachesRead = StoreReadReachability::storeReachesRead/2;

0 commit comments

Comments
 (0)