Skip to content

Commit 4e155f8

Browse files
committed
Dataflow: Insert a few getApprox calls to remove ApApprox from fwdFlow.
1 parent 231bf9d commit 4e155f8

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

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

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,26 +1479,27 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
14791479
*/
14801480
pragma[nomagic]
14811481
additional predicate fwdFlow(
1482-
NodeEx node, FlowState state, Cc cc, SummaryCtx summaryCtx, Typ t, Ap ap, ApApprox apa,
1483-
TypOption stored
1482+
NodeEx node, FlowState state, Cc cc, SummaryCtx summaryCtx, Typ t, Ap ap, TypOption stored
14841483
) {
1485-
fwdFlow1(node, state, cc, summaryCtx, _, t, ap, apa, stored)
1484+
fwdFlow1(node, state, cc, summaryCtx, _, t, ap, stored)
14861485
}
14871486

14881487
private predicate fwdFlow1(
14891488
NodeEx node, FlowState state, Cc cc, SummaryCtx summaryCtx, Typ t0, Typ t, Ap ap,
1490-
ApApprox apa, TypOption stored
1489+
TypOption stored
14911490
) {
1492-
fwdFlow0(node, state, cc, summaryCtx, t0, ap, apa, stored) and
1493-
PrevStage::revFlow(node, state, apa) and
1494-
filter(node, state, t0, ap, t) and
1495-
(
1496-
if node instanceof CastingNodeEx
1497-
then
1498-
ap instanceof ApNil or
1499-
compatibleContainer(getHeadContent(ap), node.getDataFlowType()) or
1500-
topTypeContent(getHeadContent(ap))
1501-
else any()
1491+
exists(ApApprox apa |
1492+
fwdFlow0(node, state, cc, summaryCtx, t0, ap, apa, stored) and
1493+
PrevStage::revFlow(node, state, apa) and
1494+
filter(node, state, t0, ap, t) and
1495+
(
1496+
if node instanceof CastingNodeEx
1497+
then
1498+
ap instanceof ApNil or
1499+
compatibleContainer(getHeadContent(ap), node.getDataFlowType()) or
1500+
topTypeContent(getHeadContent(ap))
1501+
else any()
1502+
)
15021503
)
15031504
}
15041505

@@ -1516,7 +1517,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
15161517
stored.isNone()
15171518
or
15181519
exists(NodeEx mid, FlowState state0, Typ t0, LocalCc localCc |
1519-
fwdFlow(mid, state0, cc, summaryCtx, t0, ap, apa, stored) and
1520+
fwdFlow(mid, state0, cc, summaryCtx, t0, ap, stored) and
1521+
apa = getApprox(ap) and
15201522
localCc = getLocalCc(cc)
15211523
|
15221524
localStep(mid, state0, node, state, true, _, localCc, _) and
@@ -1526,7 +1528,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
15261528
ap instanceof ApNil
15271529
)
15281530
or
1529-
fwdFlowJump(node, state, t, ap, apa, stored) and
1531+
fwdFlowJump(node, state, t, ap, stored) and
1532+
apa = getApprox(ap) and
15301533
cc = ccNone() and
15311534
summaryCtx = TSummaryCtxNone()
15321535
or
@@ -1615,23 +1618,21 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
16151618
override Location getLocation() { result = p.getLocation() }
16161619
}
16171620

1618-
private predicate fwdFlowJump(
1619-
NodeEx node, FlowState state, Typ t, Ap ap, ApApprox apa, TypOption stored
1620-
) {
1621+
private predicate fwdFlowJump(NodeEx node, FlowState state, Typ t, Ap ap, TypOption stored) {
16211622
exists(NodeEx mid |
1622-
fwdFlow(mid, state, _, _, t, ap, apa, stored) and
1623+
fwdFlow(mid, state, _, _, t, ap, stored) and
16231624
jumpStepEx(mid, node)
16241625
)
16251626
or
16261627
exists(NodeEx mid |
1627-
fwdFlow(mid, state, _, _, _, ap, apa, stored) and
1628+
fwdFlow(mid, state, _, _, _, ap, stored) and
16281629
additionalJumpStep(mid, node, _) and
16291630
t = getNodeTyp(node) and
16301631
ap instanceof ApNil
16311632
)
16321633
or
16331634
exists(NodeEx mid, FlowState state0 |
1634-
fwdFlow(mid, state0, _, _, _, ap, apa, stored) and
1635+
fwdFlow(mid, state0, _, _, _, ap, stored) and
16351636
additionalJumpStateStep(mid, state0, node, state, _) and
16361637
t = getNodeTyp(node) and
16371638
ap instanceof ApNil
@@ -1644,7 +1645,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
16441645
NodeEx node2, FlowState state, Cc cc, SummaryCtx summaryCtx
16451646
) {
16461647
exists(DataFlowType contentType, DataFlowType containerType |
1647-
fwdFlow(node1, state, cc, summaryCtx, t1, ap1, _, stored1) and
1648+
fwdFlow(node1, state, cc, summaryCtx, t1, ap1, stored1) and
16481649
not outBarrier(node1, state) and
16491650
not inBarrier(node2, state) and
16501651
PrevStage::storeStepCand(node1, c, node2, contentType, containerType) and
@@ -1685,7 +1686,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
16851686
Cc cc, SummaryCtx summaryCtx
16861687
) {
16871688
exists(ApHeadContent apc |
1688-
fwdFlow(node1, state, cc, summaryCtx, t, ap, _, stored) and
1689+
fwdFlow(node1, state, cc, summaryCtx, t, ap, stored) and
16891690
not outBarrier(node1, state) and
16901691
not inBarrier(node2, state) and
16911692
apc = getHeadContent(ap) and
@@ -1716,7 +1717,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
17161717
ArgNodeEx arg, FlowState state, Cc outercc, SummaryCtx summaryCtx, Typ t, Ap ap,
17171718
boolean emptyAp, TypOption stored, boolean cc
17181719
) {
1719-
fwdFlow(arg, state, outercc, summaryCtx, t, ap, _, stored) and
1720+
fwdFlow(arg, state, outercc, summaryCtx, t, ap, stored) and
17201721
(if instanceofCcCall(outercc) then cc = true else cc = false) and
17211722
if ap instanceof ApNil then emptyAp = true else emptyAp = false
17221723
}
@@ -1940,7 +1941,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
19401941
) {
19411942
instanceofCcNoCall(cc) and
19421943
not outBarrier(ret, state) and
1943-
fwdFlow(ret, state, cc, summaryCtx, t, ap, _, stored)
1944+
fwdFlow(ret, state, cc, summaryCtx, t, ap, stored)
19441945
}
19451946

19461947
pragma[nomagic]
@@ -2003,7 +2004,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
20032004
ParamNodeEx p, FlowState state, CcCall cc, Typ t0, Ap ap, TypOption stored
20042005
) {
20052006
instanceofCcCall(cc) and
2006-
fwdFlow1(p, state, cc, _, t0, _, ap, _, stored)
2007+
fwdFlow1(p, state, cc, _, t0, _, ap, stored)
20072008
}
20082009

20092010
pragma[nomagic]
@@ -2026,7 +2027,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
20262027
private predicate fwdFlow1Out(
20272028
NodeEx node, FlowState state, Cc cc, Typ t0, Ap ap, TypOption stored
20282029
) {
2029-
fwdFlow1(node, state, cc, _, t0, _, ap, _, stored) and
2030+
fwdFlow1(node, state, cc, _, t0, _, ap, stored) and
20302031
PrevStage::callEdgeReturn(_, _, _, _, node, _)
20312032
}
20322033

@@ -2048,7 +2049,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
20482049
or
20492050
exists(NodeEx node |
20502051
cc = false and
2051-
fwdFlowJump(node, _, _, _, _, _) and
2052+
fwdFlowJump(node, _, _, _, _) and
20522053
c = node.getEnclosingCallable()
20532054
)
20542055
}
@@ -2070,7 +2071,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
20702071
) {
20712072
exists(ReturnKindExt kind, ParamNodeEx p, Ap argAp |
20722073
instanceofCcCall(ccc) and
2073-
fwdFlow(pragma[only_bind_into](ret), state, ccc, summaryCtx, t, ap, _, stored) and
2074+
fwdFlow(pragma[only_bind_into](ret), state, ccc, summaryCtx, t, ap, stored) and
20742075
summaryCtx =
20752076
TSummaryCtxSome(pragma[only_bind_into](p), _, _, pragma[only_bind_into](argAp), _) and
20762077
not outBarrier(ret, state) and
@@ -2164,7 +2165,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21642165
returnFlowsThrough(_, _, _, _, pragma[only_bind_into](p), pragma[only_bind_into](argT),
21652166
pragma[only_bind_into](argAp), pragma[only_bind_into](argStored), ap) and
21662167
flowIntoCallApaTaken(call, _, pragma[only_bind_into](arg), p, emptyArgAp) and
2167-
fwdFlow(arg, _, _, _, pragma[only_bind_into](argT), pragma[only_bind_into](argAp), _,
2168+
fwdFlow(arg, _, _, _, pragma[only_bind_into](argT), pragma[only_bind_into](argAp),
21682169
pragma[only_bind_into](argStored)) and
21692170
if argAp instanceof ApNil then emptyArgAp = true else emptyArgAp = false
21702171
)
@@ -2176,7 +2177,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21762177
) {
21772178
exists(boolean emptyAp |
21782179
flowIntoCallApaTaken(call, c, arg, p, emptyAp) and
2179-
fwdFlow(arg, _, _, _, _, ap, _, _) and
2180+
fwdFlow(arg, _, _, _, _, ap, _) and
21802181
if ap instanceof ApNil then emptyAp = true else emptyAp = false
21812182
)
21822183
}
@@ -2187,7 +2188,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21872188
Ap ap, boolean allowsFieldFlow
21882189
) {
21892190
PrevStage::callEdgeReturn(call, c, ret, _, out, allowsFieldFlow) and
2190-
fwdFlow(ret, _, _, _, _, ap, _, _) and
2191+
fwdFlow(ret, _, _, _, _, ap, _) and
21912192
pos = ret.getReturnPosition() and
21922193
(if allowsFieldFlow = false then ap instanceof ApNil else any()) and
21932194
(
@@ -2210,14 +2211,14 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
22102211
NodeEx node, FlowState state, ReturnCtx returnCtx, ApOption returnAp, Ap ap
22112212
) {
22122213
revFlow0(node, state, returnCtx, returnAp, ap) and
2213-
fwdFlow(node, state, _, _, _, ap, _, _)
2214+
fwdFlow(node, state, _, _, _, ap, _)
22142215
}
22152216

22162217
pragma[nomagic]
22172218
private predicate revFlow0(
22182219
NodeEx node, FlowState state, ReturnCtx returnCtx, ApOption returnAp, Ap ap
22192220
) {
2220-
fwdFlow(node, state, _, _, _, ap, _, _) and
2221+
fwdFlow(node, state, _, _, _, ap, _) and
22212222
sinkNode(node, state) and
22222223
(
22232224
if hasSinkCallCtx()
@@ -2345,7 +2346,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
23452346

23462347
predicate dataFlowNonCallEntry(DataFlowCallable c, boolean cc) {
23472348
exists(NodeEx node, FlowState state, ApNil nil |
2348-
fwdFlow(node, state, _, _, _, nil, _, _) and
2349+
fwdFlow(node, state, _, _, _, nil, _) and
23492350
sinkNode(node, state) and
23502351
(if hasSinkCallCtx() then cc = true else cc = false) and
23512352
c = node.getEnclosingCallable()
@@ -2520,7 +2521,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25202521
exists(Ap ap0 |
25212522
parameterMayFlowThrough(p, _) and
25222523
revFlow(n, state, TReturnCtxMaybeFlowThrough(_), _, ap0) and
2523-
fwdFlow(n, state, any(CcCall ccc), TSummaryCtxSome(p, _, _, ap, _), _, ap0, _, _)
2524+
fwdFlow(n, state, any(CcCall ccc), TSummaryCtxSome(p, _, _, ap, _), _, ap0, _)
25242525
)
25252526
}
25262527

@@ -2812,7 +2813,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
28122813
NodeEx node, FlowState state, Cc cc, SummaryCtx summaryCtx, Typ t, Ap ap,
28132814
TypOption stored
28142815
) {
2815-
fwdFlow(node, state, cc, summaryCtx, t, ap, _, stored) and
2816+
fwdFlow(node, state, cc, summaryCtx, t, ap, stored) and
28162817
revFlow(node, state, _, _, ap)
28172818
} or
28182819
TPathNodeSink(NodeEx node, FlowState state) {
@@ -3148,7 +3149,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
31483149
TypOption stored
31493150
) {
31503151
exists(Typ t |
3151-
fwdFlow1(node, state, cc, summaryCtx, t0, t, ap, _, stored) and
3152+
fwdFlow1(node, state, cc, summaryCtx, t0, t, ap, stored) and
31523153
result = TPathNodeMid(node, state, cc, summaryCtx, t, ap, stored)
31533154
)
31543155
}
@@ -3598,13 +3599,13 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
35983599
int tfnodes, int tftuples
35993600
) {
36003601
fwd = true and
3601-
nodes = count(NodeEx node | fwdFlow(node, _, _, _, _, _, _, _)) and
3602+
nodes = count(NodeEx node | fwdFlow(node, _, _, _, _, _, _)) and
36023603
fields = count(Content f0 | fwdConsCand(f0, _)) and
36033604
conscand = count(Content f0, Ap ap | fwdConsCand(f0, ap)) and
3604-
states = count(FlowState state | fwdFlow(_, state, _, _, _, _, _, _)) and
3605+
states = count(FlowState state | fwdFlow(_, state, _, _, _, _, _)) and
36053606
tuples =
36063607
count(NodeEx n, FlowState state, Cc cc, SummaryCtx summaryCtx, Typ t, Ap ap,
3607-
TypOption stored | fwdFlow(n, state, cc, summaryCtx, t, ap, _, stored)) and
3608+
TypOption stored | fwdFlow(n, state, cc, summaryCtx, t, ap, stored)) and
36083609
calledges =
36093610
count(DataFlowCall call, DataFlowCallable c |
36103611
FwdTypeFlowInput::dataFlowTakenCallEdgeIn(call, c, _) or

0 commit comments

Comments
 (0)