Skip to content

Commit dd49fc9

Browse files
authored
Merge pull request #17325 from aschackmull/dataflow/state-in-summary
Dataflow: Include FlowState in SummaryCtx.
2 parents 7f8e6bf + 6a9bd0d commit dd49fc9

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
15651565
fwdFlowIn(node, apa, state, cc, t, ap, allowsFlowThrough) and
15661566
if allowsFlowThrough = true
15671567
then (
1568-
summaryCtx = TSummaryCtxSome(node, t, ap)
1568+
summaryCtx = TSummaryCtxSome(node, state, t, ap)
15691569
) else (
15701570
summaryCtx = TSummaryCtxNone() and
15711571
// When the call contexts of source and sink needs to match then there's
@@ -1592,7 +1592,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
15921592

15931593
private newtype TSummaryCtx =
15941594
TSummaryCtxNone() or
1595-
TSummaryCtxSome(ParamNodeEx p, Typ t, Ap ap) { fwdFlowIn(p, _, _, _, t, ap, true) }
1595+
TSummaryCtxSome(ParamNodeEx p, FlowState state, Typ t, Ap ap) {
1596+
fwdFlowIn(p, _, state, _, t, ap, true)
1597+
}
15961598

15971599
/**
15981600
* A context for generating flow summaries. This represents flow entry through
@@ -1616,10 +1618,11 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
16161618
/** A summary context from which a flow summary can be generated. */
16171619
private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
16181620
private ParamNodeEx p;
1621+
private FlowState state;
16191622
private Typ t;
16201623
private Ap ap;
16211624

1622-
SummaryCtxSome() { this = TSummaryCtxSome(p, t, ap) }
1625+
SummaryCtxSome() { this = TSummaryCtxSome(p, state, t, ap) }
16231626

16241627
ParamNodeEx getParamNode() { result = p }
16251628

@@ -2074,7 +2077,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
20742077
fwdFlow(pragma[only_bind_into](ret), state, ccc, summaryCtx, t, ap,
20752078
pragma[only_bind_into](apa)) and
20762079
summaryCtx =
2077-
TSummaryCtxSome(pragma[only_bind_into](p), _, pragma[only_bind_into](argAp)) and
2080+
TSummaryCtxSome(pragma[only_bind_into](p), _, _, pragma[only_bind_into](argAp)) and
20782081
not outBarrier(ret, state) and
20792082
kind = ret.getKind() and
20802083
parameterFlowThroughAllowed(p, kind) and
@@ -2110,9 +2113,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21102113
pragma[nomagic]
21112114
private predicate fwdFlowIsEntered0(
21122115
DataFlowCall call, ArgNodeEx arg, Cc cc, CcCall innerCc, SummaryCtx summaryCtx,
2113-
ParamNodeEx p, Typ t, Ap ap
2116+
ParamNodeEx p, FlowState state, Typ t, Ap ap
21142117
) {
2115-
FwdFlowIn<FwdFlowThroughRestriction>::fwdFlowIn(call, arg, _, p, _, cc, innerCc,
2118+
FwdFlowIn<FwdFlowThroughRestriction>::fwdFlowIn(call, arg, _, p, state, cc, innerCc,
21162119
summaryCtx, t, ap, _, _, true)
21172120
}
21182121

@@ -2125,9 +2128,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21252128
DataFlowCall call, ArgNodeEx arg, Cc cc, CcCall innerCc, SummaryCtx summaryCtx,
21262129
SummaryCtxSome innerSummaryCtx
21272130
) {
2128-
exists(ParamNodeEx p, Typ t, Ap ap |
2129-
fwdFlowIsEntered0(call, arg, cc, innerCc, summaryCtx, p, t, ap) and
2130-
innerSummaryCtx = TSummaryCtxSome(p, t, ap)
2131+
exists(ParamNodeEx p, FlowState state, Typ t, Ap ap |
2132+
fwdFlowIsEntered0(call, arg, cc, innerCc, summaryCtx, p, state, t, ap) and
2133+
innerSummaryCtx = TSummaryCtxSome(p, state, t, ap)
21312134
)
21322135
}
21332136

@@ -2160,7 +2163,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
21602163
Ap argAp, ApApprox argApa, Ap ap
21612164
) {
21622165
exists(DataFlowCall call, ApApprox apa, boolean allowsFieldFlow |
2163-
returnFlowsThrough0(call, state, ccc, ap, apa, ret, TSummaryCtxSome(p, argT, argAp),
2166+
returnFlowsThrough0(call, state, ccc, ap, apa, ret, TSummaryCtxSome(p, _, argT, argAp),
21642167
argApa) and
21652168
flowThroughOutOfCall(call, ccc, ret, _, allowsFieldFlow, argApa, apa) and
21662169
pos = ret.getReturnPosition() and
@@ -2522,7 +2525,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
25222525
exists(Ap ap0 |
25232526
parameterMayFlowThrough(p, _) and
25242527
revFlow(n, state, TReturnCtxMaybeFlowThrough(_), _, ap0) and
2525-
fwdFlow(n, state, any(CcCall ccc), TSummaryCtxSome(p, _, ap), _, ap0, _)
2528+
fwdFlow(n, state, any(CcCall ccc), TSummaryCtxSome(p, _, _, ap), _, ap0, _)
25262529
)
25272530
}
25282531

@@ -3114,8 +3117,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
31143117
|
31153118
fwdFlowThroughStep0(call, arg, cc, state, ccc, summaryCtx, t, ap, apa, ret,
31163119
innerSummaryCtx, innerArgApa) and
3117-
innerSummaryCtx = TSummaryCtxSome(p, innerArgT, innerArgAp) and
3118-
revFlow(arg, state0, _, _, _) and
3120+
innerSummaryCtx = TSummaryCtxSome(p, state0, innerArgT, innerArgAp) and
31193121
pn1 = mkPathNode(arg, state0, cc, summaryCtx, innerArgT, innerArgAp) and
31203122
pn2 = typeStrengthenToPathNode(p, state0, ccc, innerSummaryCtx, innerArgT, innerArgAp) and
31213123
pn3 = mkPathNode(ret, state, ccc, innerSummaryCtx, t, ap)
@@ -3244,7 +3246,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
32443246
fwdFlowInStep(arg, node, state, outercc, cc, outerSummaryCtx, t, ap, allowsFlowThrough) and
32453247
label = "" and
32463248
if allowsFlowThrough = true
3247-
then summaryCtx = TSummaryCtxSome(node, t, ap)
3249+
then summaryCtx = TSummaryCtxSome(node, state, t, ap)
32483250
else summaryCtx = TSummaryCtxNone()
32493251
)
32503252
or

0 commit comments

Comments
 (0)