Skip to content

Commit adc738c

Browse files
committed
Data flow: Simplify reverse flow-through pruning
1 parent d34901a commit adc738c

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowImpl.qll

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,12 +1529,8 @@ private module MkStage<StageSig PrevStage> {
15291529
ApOption argAp, Ap ap, ApApprox apa, RetNodeEx ret, ParamNodeEx innerSummaryCtx,
15301530
Ap innerArgAp, ApApprox innerArgApa, Configuration config
15311531
) {
1532-
fwdFlowRetFromArg(pragma[only_bind_into](ret), state, pragma[only_bind_into](ccc),
1533-
innerSummaryCtx, innerArgAp, innerArgApa, ap, pragma[only_bind_into](apa),
1534-
pragma[only_bind_into](config)) and
1535-
fwdFlowIsEntered(call, cc, ccc, summaryCtx, argAp, innerSummaryCtx, innerArgAp,
1536-
pragma[only_bind_into](config)) and
1537-
matchesCall(ccc, call)
1532+
fwdFlowRetFromArg(ret, state, ccc, innerSummaryCtx, innerArgAp, innerArgApa, ap, apa, config) and
1533+
fwdFlowIsEntered(call, cc, ccc, summaryCtx, argAp, innerSummaryCtx, innerArgAp, config)
15381534
}
15391535

15401536
pragma[nomagic]
@@ -1603,15 +1599,15 @@ private module MkStage<StageSig PrevStage> {
16031599

16041600
pragma[nomagic]
16051601
private predicate flowThroughIntoCall(
1606-
DataFlowCall call, ArgNodeEx arg, ParamNodeEx p, boolean allowsFieldFlow, Ap argAp,
1602+
DataFlowCall call, ArgNodeEx arg, ParamNodeEx p, boolean allowsFieldFlow, Ap argAp, Ap ap,
16071603
Configuration config
16081604
) {
16091605
exists(ApApprox argApa |
16101606
flowIntoCallApa(call, pragma[only_bind_into](arg), pragma[only_bind_into](p),
16111607
allowsFieldFlow, argApa, pragma[only_bind_into](config)) and
16121608
fwdFlow(arg, _, _, _, _, pragma[only_bind_into](argAp), argApa,
16131609
pragma[only_bind_into](config)) and
1614-
returnFlowsThrough(_, _, _, _, p, pragma[only_bind_into](argAp), _,
1610+
returnFlowsThrough(_, _, _, _, p, pragma[only_bind_into](argAp), ap,
16151611
pragma[only_bind_into](config)) and
16161612
if allowsFieldFlow = false then argAp instanceof ApNil else any()
16171613
)
@@ -1731,9 +1727,9 @@ private module MkStage<StageSig PrevStage> {
17311727
)
17321728
or
17331729
// flow through a callable
1734-
exists(DataFlowCall call, ReturnPosition pos, Ap returnAp0 |
1735-
revFlowInToReturn(call, node, state, pos, returnAp0, ap, config) and
1736-
revFlowIsReturned(call, returnCtx, returnAp, pos, returnAp0, config)
1730+
exists(DataFlowCall call, ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1731+
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1732+
flowThroughIntoCall(call, node, p, _, ap, innerReturnAp, config)
17371733
)
17381734
or
17391735
// flow out of a callable
@@ -1784,37 +1780,23 @@ private module MkStage<StageSig PrevStage> {
17841780
)
17851781
}
17861782

1787-
/**
1788-
* Same as `flowThroughIntoCall`, but restricted to calls that are reached
1789-
* in the flow covered by `revFlow`, where data might flow through the target
1790-
* callable and back out at `call`.
1791-
*/
1792-
pragma[nomagic]
1793-
private predicate revFlowThroughIntoCall(
1794-
DataFlowCall call, ArgNodeEx arg, ParamNodeEx p, boolean allowsFieldFlow, Ap argAp,
1795-
Configuration config
1796-
) {
1797-
flowThroughIntoCall(call, arg, p, allowsFieldFlow, argAp, config) and
1798-
revFlowIsReturned(call, _, _, _, _, config)
1799-
}
1800-
18011783
pragma[nomagic]
18021784
private predicate revFlowParamToReturn(
18031785
ParamNodeEx p, FlowState state, ReturnPosition pos, Ap returnAp, Ap ap, Configuration config
18041786
) {
1805-
revFlow(p, state, TReturnCtxMaybeFlowThrough(pos), apSome(returnAp), ap, config) and
1806-
parameterFlowThroughAllowed(p, pos.getKind())
1787+
revFlow(pragma[only_bind_into](p), state, TReturnCtxMaybeFlowThrough(pos), apSome(returnAp),
1788+
pragma[only_bind_into](ap), pragma[only_bind_into](config)) and
1789+
parameterFlowThroughAllowed(p, pos.getKind()) and
1790+
PrevStage::parameterMayFlowThrough(p, getApprox(ap), config)
18071791
}
18081792

18091793
pragma[nomagic]
1810-
private predicate revFlowInToReturn(
1811-
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnPosition pos, Ap returnAp, Ap ap,
1812-
Configuration config
1794+
private predicate revFlowThrough(
1795+
DataFlowCall call, ReturnCtx returnCtx, ParamNodeEx p, FlowState state, ReturnPosition pos,
1796+
ApOption returnAp, Ap ap, Ap innerReturnAp, Configuration config
18131797
) {
1814-
exists(ParamNodeEx p, boolean allowsFieldFlow |
1815-
revFlowParamToReturn(p, state, pos, returnAp, ap, config) and
1816-
revFlowThroughIntoCall(call, arg, p, allowsFieldFlow, ap, config)
1817-
)
1798+
revFlowParamToReturn(p, state, pos, innerReturnAp, ap, config) and
1799+
revFlowIsReturned(call, returnCtx, returnAp, pos, innerReturnAp, config)
18181800
}
18191801

18201802
/**
@@ -1933,21 +1915,21 @@ private module MkStage<StageSig PrevStage> {
19331915
}
19341916

19351917
pragma[nomagic]
1936-
predicate revFlowInToReturnIsReturned(
1918+
private predicate revFlowThroughArg(
19371919
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
19381920
Ap ap, Configuration config
19391921
) {
1940-
exists(ReturnPosition pos, Ap returnAp0 |
1941-
revFlowInToReturn(call, arg, state, pos, returnAp0, ap, config) and
1942-
revFlowIsReturned(call, returnCtx, returnAp, pos, returnAp0, config)
1922+
exists(ParamNodeEx p, ReturnPosition pos, Ap innerReturnAp |
1923+
revFlowThrough(call, returnCtx, p, state, pos, returnAp, ap, innerReturnAp, config) and
1924+
flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp, config)
19431925
)
19441926
}
19451927

19461928
pragma[nomagic]
19471929
predicate callMayFlowThroughRev(DataFlowCall call, Configuration config) {
19481930
exists(ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp, Ap ap |
19491931
revFlow(arg, state, returnCtx, returnAp, ap, config) and
1950-
revFlowInToReturnIsReturned(call, arg, state, returnCtx, returnAp, ap, config)
1932+
revFlowThroughArg(call, arg, state, returnCtx, returnAp, ap, config)
19511933
)
19521934
}
19531935

0 commit comments

Comments
 (0)