Skip to content

Commit d8dbafb

Browse files
committed
Data flow: Depth 1 call contexts in store/load matching
1 parent ce13b35 commit d8dbafb

File tree

2 files changed

+135
-75
lines changed

2 files changed

+135
-75
lines changed

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

+59-23
Original file line numberDiff line numberDiff line change
@@ -2559,23 +2559,25 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25592559

25602560
pragma[nomagic]
25612561
private predicate revFlowThroughArg(
2562-
DataFlowCall call, ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp,
2563-
Ap ap
2562+
DataFlowCall call, ArgNodeEx arg, ParamNodeEx p, FlowState state, ReturnCtx returnCtx,
2563+
ApOption returnAp, Ap ap
25642564
) {
2565-
exists(ParamNodeEx p, Ap innerReturnAp |
2565+
exists(Ap innerReturnAp |
25662566
revFlowThrough(call, returnCtx, p, state, _, returnAp, ap, innerReturnAp) and
25672567
flowThroughIntoCall(call, arg, p, _, ap, innerReturnAp)
25682568
)
25692569
}
25702570

25712571
pragma[nomagic]
2572-
predicate callMayFlowThroughRev(DataFlowCall call) {
2572+
additional predicate callMayFlowThroughRev(DataFlowCall call, ParamNodeEx p) {
25732573
exists(ArgNodeEx arg, FlowState state, ReturnCtx returnCtx, ApOption returnAp, Ap ap |
25742574
revFlow(arg, state, returnCtx, returnAp, ap) and
2575-
revFlowThroughArg(call, arg, state, returnCtx, returnAp, ap)
2575+
revFlowThroughArg(call, arg, p, state, returnCtx, returnAp, ap)
25762576
)
25772577
}
25782578

2579+
predicate callMayFlowThroughRev(DataFlowCall call) { callMayFlowThroughRev(call, _) }
2580+
25792581
predicate callEdgeArgParam(
25802582
DataFlowCall call, DataFlowCallable c, ArgNodeEx arg, ParamNodeEx p,
25812583
boolean allowsFieldFlow, Ap ap
@@ -3416,24 +3418,51 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
34163418
private module StoreReadMatchingInput implements StoreReadMatchingInputSig {
34173419
class NodeEx = NodeExAlias;
34183420

3419-
predicate nodeRange(NodeEx node, boolean fromArg) {
3420-
exists(PrevStage::Ap ap |
3421-
PrevStage::revFlowAp(node, ap) and
3421+
pragma[nomagic]
3422+
private DataFlowCallOption getAFlowThroughCallCtx(
3423+
NodeEx node, PrevStage::Ap ap, boolean fromArg
3424+
) {
3425+
exists(PrevStage::Cc cc, ParamNodeOption summaryCtx, PrevStage::ApOption argAp |
3426+
PrevStage::fwdFlow(node, _, cc, summaryCtx, _, argAp, _, ap, _)
3427+
|
3428+
PrevStage::instanceofCcCall(cc) and
3429+
fromArg = true and
34223430
(
3423-
ap = true
3424-
or
3425-
PrevStage::storeStepCand(node, ap, _, _, _, _)
3431+
summaryCtx instanceof TParamNodeNone and
3432+
result = TDataFlowCallNone()
34263433
or
3427-
PrevStage::readStepCand(_, _, node)
3434+
exists(ParamNodeEx p, PrevStage::Ap argApSome |
3435+
summaryCtx = TParamNodeSome(p.asNode()) and
3436+
argAp = PrevStage::apSome(argApSome)
3437+
|
3438+
if
3439+
PrevStage::parameterMayFlowThrough(p, argApSome) and
3440+
PrevStage::callMayFlowThroughRev(_, p)
3441+
then
3442+
exists(DataFlowCall call |
3443+
PrevStage::callMayFlowThroughRev(call, p) and
3444+
result = TDataFlowCallSome(call)
3445+
)
3446+
else result = TDataFlowCallNone()
3447+
)
34283448
)
3449+
or
3450+
PrevStage::instanceofCcNoCall(cc) and
3451+
fromArg = false and
3452+
result = TDataFlowCallNone()
3453+
)
3454+
}
3455+
3456+
predicate nodeRange(NodeEx node, boolean fromArg, DataFlowCallOption summaryCtx) {
3457+
exists(PrevStage::Ap ap |
3458+
PrevStage::revFlowAp(node, ap) and
3459+
summaryCtx = getAFlowThroughCallCtx(node, ap, fromArg)
34293460
|
3430-
exists(PrevStage::Cc cc | PrevStage::fwdFlow(node, _, cc, _, _, _, _, ap, _) |
3431-
PrevStage::instanceofCcCall(cc) and
3432-
fromArg = true
3433-
or
3434-
PrevStage::instanceofCcNoCall(cc) and
3435-
fromArg = false
3436-
)
3461+
ap = true
3462+
or
3463+
PrevStage::storeStepCand(node, ap, _, _, _, _)
3464+
or
3465+
PrevStage::readStepCand(_, _, node)
34373466
)
34383467
}
34393468

@@ -3459,12 +3488,19 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
34593488
)
34603489
}
34613490

3462-
predicate callEdgeArgParam(NodeEx arg, NodeEx param) {
3463-
PrevStage::callEdgeArgParam(_, _, arg, param, true, true)
3491+
predicate callEdgeArgParam(NodeEx arg, NodeEx param, DataFlowCallOption summaryCtx) {
3492+
exists(DataFlowCall call |
3493+
PrevStage::callEdgeArgParam(call, _, arg, param, true, true) and
3494+
summaryCtx = getAFlowThroughCallCtx(param, true, true)
3495+
|
3496+
summaryCtx = TDataFlowCallNone()
3497+
or
3498+
summaryCtx = TDataFlowCallSome(call)
3499+
)
34643500
}
34653501

3466-
predicate callEdgeReturn(NodeEx ret, NodeEx out, boolean mayFlowThrough) {
3467-
PrevStage::callEdgeReturn(_, _, ret, _, out, true, true) and
3502+
predicate callEdgeReturn(DataFlowCall call, NodeEx ret, NodeEx out, boolean mayFlowThrough) {
3503+
PrevStage::callEdgeReturn(call, _, ret, _, out, true, true) and
34683504
if flowThroughOutOfCall(ret, out) then mayFlowThrough = true else mayFlowThrough = false
34693505
}
34703506

0 commit comments

Comments
 (0)