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

Skip to content

Commit 0a60a3a

Browse files
committed
Dataflow: Align on ApNil.
1 parent 60b5101 commit 0a60a3a

1 file changed

Lines changed: 47 additions & 36 deletions

File tree

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

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ private module Stage2 {
745745

746746
class Ap = boolean;
747747

748+
class ApNil extends Ap {
749+
ApNil() { this = false }
750+
}
751+
748752
class ApOption = BooleanOption;
749753

750754
ApOption apNone() { result = TBooleanNone() }
@@ -858,7 +862,7 @@ private module Stage2 {
858862
fwdFlow(arg, cc, argAp, ap, config) and
859863
flowIntoCallNodeCand1(call, arg, p, allowsFieldFlow, config)
860864
|
861-
ap = false or allowsFieldFlow = true
865+
ap instanceof ApNil or allowsFieldFlow = true
862866
)
863867
}
864868

@@ -870,7 +874,7 @@ private module Stage2 {
870874
fwdFlow(ret, cc, argAp, ap, config) and
871875
flowOutOfCallNodeCand1(call, ret, out, allowsFieldFlow, config)
872876
|
873-
ap = false or allowsFieldFlow = true
877+
ap instanceof ApNil or allowsFieldFlow = true
874878
)
875879
}
876880

@@ -903,6 +907,7 @@ private module Stage2 {
903907
* the enclosing callable in order to reach a sink, and if so, `returnAp`
904908
* records whether a field must be read from the returned value.
905909
*/
910+
pragma[nomagic]
906911
predicate revFlow(Node node, boolean toReturn, ApOption returnAp, Ap ap, Configuration config) {
907912
revFlow0(node, toReturn, returnAp, ap, config) and
908913
fwdFlow(node, _, _, ap, config)
@@ -916,17 +921,18 @@ private module Stage2 {
916921
config.isSink(node) and
917922
toReturn = false and
918923
returnAp = apNone() and
919-
ap = false
924+
ap instanceof ApNil
920925
or
921926
exists(Node mid |
922927
localFlowStepNodeCand1(node, mid, config) and
923928
revFlow(mid, toReturn, returnAp, ap, config)
924929
)
925930
or
926-
exists(Node mid |
931+
exists(Node mid, ApNil nil |
932+
fwdFlow(node, _, _, ap, config) and
927933
additionalLocalFlowStepNodeCand1(node, mid, config) and
928-
revFlow(mid, toReturn, returnAp, ap, config) and
929-
ap = false
934+
revFlow(mid, toReturn, returnAp, nil, config) and
935+
ap instanceof ApNil
930936
)
931937
or
932938
exists(Node mid |
@@ -936,12 +942,13 @@ private module Stage2 {
936942
returnAp = apNone()
937943
)
938944
or
939-
exists(Node mid |
945+
exists(Node mid, ApNil nil |
946+
fwdFlow(node, _, _, ap, config) and
940947
additionalJumpStep(node, mid, config) and
941-
revFlow(mid, _, _, ap, config) and
948+
revFlow(mid, _, _, nil, config) and
942949
toReturn = false and
943950
returnAp = apNone() and
944-
ap = false
951+
ap instanceof ApNil
945952
)
946953
or
947954
// store
@@ -963,7 +970,7 @@ private module Stage2 {
963970
revFlowIn(call, node, toReturn, returnAp, ap, config) and
964971
toReturn = false
965972
or
966-
exists(boolean returnAp0 |
973+
exists(Ap returnAp0 |
967974
revFlowInToReturn(call, node, returnAp0, ap, config) and
968975
revFlowIsReturned(call, toReturn, returnAp, returnAp0, config)
969976
)
@@ -1034,7 +1041,7 @@ private module Stage2 {
10341041
revFlow(out, toReturn, returnAp, ap, config) and
10351042
flowOutOfCallNodeCand1(call, ret, out, allowsFieldFlow, config)
10361043
|
1037-
ap = false or allowsFieldFlow = true
1044+
ap instanceof ApNil or allowsFieldFlow = true
10381045
)
10391046
}
10401047

@@ -1047,13 +1054,13 @@ private module Stage2 {
10471054
revFlow(p, toReturn, returnAp, ap, config) and
10481055
flowIntoCallNodeCand1(call, arg, p, allowsFieldFlow, config)
10491056
|
1050-
ap = false or allowsFieldFlow = true
1057+
ap instanceof ApNil or allowsFieldFlow = true
10511058
)
10521059
}
10531060

10541061
pragma[nomagic]
10551062
private predicate revFlowInToReturn(
1056-
DataFlowCall call, ArgumentNode arg, boolean returnAp, Ap ap, Configuration config
1063+
DataFlowCall call, ArgumentNode arg, Ap returnAp, Ap ap, Configuration config
10571064
) {
10581065
revFlowIn(call, arg, true, apSome(returnAp), ap, config)
10591066
}
@@ -1236,6 +1243,8 @@ private module Stage3 {
12361243

12371244
class Ap = AccessPathFront;
12381245

1246+
class ApNil = AccessPathFrontNil;
1247+
12391248
class ApOption = AccessPathFrontOption;
12401249

12411250
ApOption apNone() { result = TAccessPathFrontNone() }
@@ -1273,7 +1282,7 @@ private module Stage3 {
12731282
localFlowBigStep(mid, node, true, _, config, _)
12741283
)
12751284
or
1276-
exists(Node mid, AccessPathFrontNil nil |
1285+
exists(Node mid, ApNil nil |
12771286
fwdFlow(mid, cc, argAp, nil, config) and
12781287
localFlowBigStep(mid, node, false, ap, config, _)
12791288
)
@@ -1286,7 +1295,7 @@ private module Stage3 {
12861295
argAp = apNone()
12871296
)
12881297
or
1289-
exists(Node mid, AccessPathFrontNil nil |
1298+
exists(Node mid, ApNil nil |
12901299
fwdFlow(mid, _, _, nil, config) and
12911300
Stage2::revFlow(node, unbind(config)) and
12921301
additionalJumpStep(mid, node, config) and
@@ -1365,7 +1374,7 @@ private module Stage3 {
13651374
fwdFlow(arg, cc, argAp, ap, config) and
13661375
flowIntoCallNodeCand2(call, arg, p, allowsFieldFlow, config)
13671376
|
1368-
ap instanceof AccessPathFrontNil or allowsFieldFlow = true
1377+
ap instanceof ApNil or allowsFieldFlow = true
13691378
)
13701379
}
13711380

@@ -1377,7 +1386,7 @@ private module Stage3 {
13771386
fwdFlow(ret, cc, argAp, ap, config) and
13781387
flowOutOfCallNodeCand2(call, ret, node, allowsFieldFlow, config)
13791388
|
1380-
ap instanceof AccessPathFrontNil or allowsFieldFlow = true
1389+
ap instanceof ApNil or allowsFieldFlow = true
13811390
)
13821391
}
13831392

@@ -1423,18 +1432,18 @@ private module Stage3 {
14231432
config.isSink(node) and
14241433
toReturn = false and
14251434
returnAp = apNone() and
1426-
ap instanceof AccessPathFrontNil
1435+
ap instanceof ApNil
14271436
or
14281437
exists(Node mid |
14291438
localFlowBigStep(node, mid, true, _, config, _) and
14301439
revFlow(mid, toReturn, returnAp, ap, config)
14311440
)
14321441
or
1433-
exists(Node mid, AccessPathFrontNil nil |
1442+
exists(Node mid, ApNil nil |
14341443
fwdFlow(node, _, _, ap, config) and
14351444
localFlowBigStep(node, mid, false, _, config, _) and
14361445
revFlow(mid, toReturn, returnAp, nil, config) and
1437-
ap instanceof AccessPathFrontNil
1446+
ap instanceof ApNil
14381447
)
14391448
or
14401449
exists(Node mid |
@@ -1444,13 +1453,13 @@ private module Stage3 {
14441453
returnAp = apNone()
14451454
)
14461455
or
1447-
exists(Node mid, AccessPathFrontNil nil |
1456+
exists(Node mid, ApNil nil |
14481457
fwdFlow(node, _, _, ap, config) and
14491458
additionalJumpStep(node, mid, config) and
14501459
revFlow(mid, _, _, nil, config) and
14511460
toReturn = false and
14521461
returnAp = apNone() and
1453-
ap instanceof AccessPathFrontNil
1462+
ap instanceof ApNil
14541463
)
14551464
or
14561465
// store
@@ -1524,7 +1533,7 @@ private module Stage3 {
15241533
revFlow(out, toReturn, returnAp, ap, config) and
15251534
flowOutOfCallNodeCand2(call, ret, out, allowsFieldFlow, config)
15261535
|
1527-
ap instanceof AccessPathFrontNil or allowsFieldFlow = true
1536+
ap instanceof ApNil or allowsFieldFlow = true
15281537
)
15291538
}
15301539

@@ -1537,7 +1546,7 @@ private module Stage3 {
15371546
revFlow(p, toReturn, returnAp, ap, config) and
15381547
flowIntoCallNodeCand2(call, arg, p, allowsFieldFlow, config)
15391548
|
1540-
ap instanceof AccessPathFrontNil or allowsFieldFlow = true
1549+
ap instanceof ApNil or allowsFieldFlow = true
15411550
)
15421551
}
15431552

@@ -1771,6 +1780,8 @@ private module Stage4 {
17711780

17721781
class Ap = AccessPathApprox;
17731782

1783+
class ApNil = AccessPathApproxNil;
1784+
17741785
class ApOption = AccessPathApproxOption;
17751786

17761787
ApOption apNone() { result = TAccessPathApproxNone() }
@@ -1807,10 +1818,10 @@ private module Stage4 {
18071818
localFlowBigStep(mid, node, true, _, config, localCC)
18081819
)
18091820
or
1810-
exists(Node mid, AccessPathApproxNil nil, LocalCallContext localCC, AccessPathFront apf |
1821+
exists(Node mid, ApNil nil, LocalCallContext localCC, AccessPathFront apf |
18111822
fwdFlowLocalEntry(mid, cc, argAp, nil, localCC, config) and
18121823
localFlowBigStep(mid, node, false, apf, config, localCC) and
1813-
apf = ap.(AccessPathApproxNil).getFront()
1824+
apf = ap.(ApNil).getFront()
18141825
)
18151826
or
18161827
exists(Node mid |
@@ -1820,7 +1831,7 @@ private module Stage4 {
18201831
argAp = apNone()
18211832
)
18221833
or
1823-
exists(Node mid, AccessPathApproxNil nil |
1834+
exists(Node mid, ApNil nil |
18241835
fwdFlow(mid, _, _, nil, config) and
18251836
additionalJumpStep(mid, node, config) and
18261837
cc instanceof CallContextAny and
@@ -1944,7 +1955,7 @@ private module Stage4 {
19441955
then innercc = TSpecificCall(call)
19451956
else innercc = TSomeCall()
19461957
|
1947-
ap instanceof AccessPathApproxNil or allowsFieldFlow = true
1958+
ap instanceof ApNil or allowsFieldFlow = true
19481959
)
19491960
}
19501961

@@ -1964,7 +1975,7 @@ private module Stage4 {
19641975
innercc.(CallContextCall).matchesCall(call)
19651976
)
19661977
|
1967-
ap instanceof AccessPathApproxNil or allowsFieldFlow = true
1978+
ap instanceof ApNil or allowsFieldFlow = true
19681979
)
19691980
}
19701981

@@ -2008,18 +2019,18 @@ private module Stage4 {
20082019
config.isSink(node) and
20092020
toReturn = false and
20102021
returnAp = apNone() and
2011-
ap instanceof AccessPathApproxNil
2022+
ap instanceof ApNil
20122023
or
20132024
exists(Node mid |
20142025
localFlowBigStep(node, mid, true, _, config, _) and
20152026
revFlow(mid, toReturn, returnAp, ap, config)
20162027
)
20172028
or
2018-
exists(Node mid, AccessPathApproxNil nil |
2029+
exists(Node mid, ApNil nil |
20192030
fwdFlow(node, _, _, ap, config) and
20202031
localFlowBigStep(node, mid, false, _, config, _) and
20212032
revFlow(mid, toReturn, returnAp, nil, config) and
2022-
ap instanceof AccessPathApproxNil
2033+
ap instanceof ApNil
20232034
)
20242035
or
20252036
exists(Node mid |
@@ -2029,13 +2040,13 @@ private module Stage4 {
20292040
returnAp = apNone()
20302041
)
20312042
or
2032-
exists(Node mid, AccessPathApproxNil nil |
2043+
exists(Node mid, ApNil nil |
20332044
fwdFlow(node, _, _, ap, config) and
20342045
additionalJumpStep(node, mid, config) and
20352046
revFlow(mid, _, _, nil, config) and
20362047
toReturn = false and
20372048
returnAp = apNone() and
2038-
ap instanceof AccessPathApproxNil
2049+
ap instanceof ApNil
20392050
)
20402051
or
20412052
// store
@@ -2118,7 +2129,7 @@ private module Stage4 {
21182129
revFlow(out, toReturn, returnAp, ap, config) and
21192130
flowOutOfCallNodeCand2(call, ret, out, allowsFieldFlow, config)
21202131
|
2121-
ap instanceof AccessPathApproxNil or allowsFieldFlow = true
2132+
ap instanceof ApNil or allowsFieldFlow = true
21222133
)
21232134
}
21242135

@@ -2131,7 +2142,7 @@ private module Stage4 {
21312142
revFlow(p, toReturn, returnAp, ap, config) and
21322143
flowIntoCallNodeCand2(call, arg, p, allowsFieldFlow, config)
21332144
|
2134-
ap instanceof AccessPathApproxNil or allowsFieldFlow = true
2145+
ap instanceof ApNil or allowsFieldFlow = true
21352146
)
21362147
}
21372148

0 commit comments

Comments
 (0)