Skip to content

Commit 97e97ba

Browse files
committed
Data flow: Rework reverse flow through parameters
1 parent fcd7555 commit 97e97ba

File tree

2 files changed

+289
-64
lines changed

2 files changed

+289
-64
lines changed

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
241241

242242
private predicate inBarrier(NodeEx node) {
243243
exists(Node n |
244-
node.asNode() = n and
244+
[node.asNode(), node.asNodeReverse()] = n and
245245
Config::isBarrierIn(n) and
246246
isRelevantSource(n, _)
247247
)
@@ -250,15 +250,15 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
250250
pragma[nomagic]
251251
private predicate inBarrier(NodeEx node, FlowState state) {
252252
exists(Node n |
253-
node.asNode() = n and
253+
[node.asNode(), node.asNodeReverse()] = n and
254254
Config::isBarrierIn(n, state) and
255255
isRelevantSource(n, state)
256256
)
257257
}
258258

259259
private predicate outBarrier(NodeEx node) {
260260
exists(Node n |
261-
node.asNodeOrImplicitRead() = n and
261+
[node.asNodeOrImplicitRead(), node.asNodeReverse()] = n and
262262
Config::isBarrierOut(n)
263263
|
264264
isRelevantSink(n, _)
@@ -270,7 +270,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
270270
pragma[nomagic]
271271
private predicate outBarrier(NodeEx node, FlowState state) {
272272
exists(Node n |
273-
node.asNodeOrImplicitRead() = n and
273+
[node.asNodeOrImplicitRead(), node.asNodeReverse()] = n and
274274
Config::isBarrierOut(n, state)
275275
|
276276
isRelevantSink(n, state)
@@ -281,7 +281,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
281281

282282
pragma[nomagic]
283283
private predicate fullBarrier(NodeEx node) {
284-
exists(Node n | node.asNode() = n |
284+
exists(Node n | [node.asNode(), node.asNodeReverse()] = n |
285285
Config::isBarrier(n)
286286
or
287287
Config::isBarrierIn(n) and
@@ -295,7 +295,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
295295

296296
pragma[nomagic]
297297
private predicate stateBarrier(NodeEx node, FlowState state) {
298-
exists(Node n | node.asNode() = n |
298+
exists(Node n | [node.asNode(), node.asNodeReverse()] = n |
299299
Config::isBarrier(n, state)
300300
or
301301
Config::isBarrierIn(n, state) and
@@ -506,8 +506,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
506506
*/
507507
bindingset[p, kind]
508508
private predicate parameterFlowThroughAllowed(ParamNodeEx p, ReturnKindExt kind) {
509-
exists(ParameterPosition pos | p.isParameterOf(_, pos) |
510-
not kind.(ParamUpdateReturnKind).getPosition() = pos
509+
exists(ParameterPositionEx pos | p.isParameterOf(_, pos) |
510+
not kind.(ParamUpdateReturnKind).getPosition() = pos.asParameterPosition()
511511
or
512512
allowParameterReturnInSelfEx(p)
513513
)
@@ -1143,7 +1143,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
11431143
|
11441144
scope = getSecondLevelScopeEx(ret)
11451145
or
1146-
ret = TParamReturnNode(_, scope)
1146+
// ret = TParamReturnNode(_, scope)
1147+
ret = TParamReturnNode(_) and
1148+
scope.isNone() // todo
11471149
)
11481150
}
11491151

@@ -2651,8 +2653,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26512653
FlowCheckNode() {
26522654
revFlow(this, _, _) and
26532655
(
2654-
flowCheckNode(this) or
2655-
Config::neverSkip(this.asNode())
2656+
flowCheckNode(this)
2657+
or
2658+
Config::neverSkip([this.asNode(), this.asNodeReverse()])
26562659
)
26572660
}
26582661
}
@@ -5445,23 +5448,23 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
54455448

54465449
pragma[noinline]
54475450
private predicate partialPathIntoArg(
5448-
PartialPathNodeFwd mid, ParameterPosition ppos, FlowState state, CallContext cc,
5451+
PartialPathNodeFwd mid, ParameterPositionEx ppos, FlowState state, CallContext cc,
54495452
DataFlowCall call, DataFlowType t, PartialAccessPath ap
54505453
) {
5451-
exists(ArgNode arg, ArgumentPosition apos |
5452-
arg = mid.getNodeEx().asNode() and
5454+
exists(ArgNodeEx arg, ArgumentPositionEx apos |
5455+
arg = mid.getNodeEx() and
54535456
state = mid.getState() and
54545457
cc = mid.getCallContext() and
54555458
arg.argumentOf(call, apos) and
54565459
t = mid.getType() and
54575460
ap = mid.getAp() and
5458-
parameterMatch(ppos, apos)
5461+
parameterMatchEx(ppos, apos)
54595462
)
54605463
}
54615464

54625465
pragma[nomagic]
54635466
private predicate partialPathIntoCallable0(
5464-
PartialPathNodeFwd mid, DataFlowCallable callable, ParameterPosition pos, FlowState state,
5467+
PartialPathNodeFwd mid, DataFlowCallable callable, ParameterPositionEx pos, FlowState state,
54655468
CallContext outercc, DataFlowCall call, DataFlowType t, PartialAccessPath ap
54665469
) {
54675470
partialPathIntoArg(mid, pos, state, outercc, call, t, ap) and
@@ -5473,7 +5476,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
54735476
CallContextCall innercc, TSummaryCtx1 sc1, TSummaryCtx2 sc2, TSummaryCtx3 sc3,
54745477
TSummaryCtx4 sc4, DataFlowCall call, DataFlowType t, PartialAccessPath ap
54755478
) {
5476-
exists(ParameterPosition pos, DataFlowCallable callable |
5479+
exists(ParameterPositionEx pos, DataFlowCallable callable |
54775480
partialPathIntoCallable0(mid, callable, pos, state, outercc, call, t, ap) and
54785481
p.isParameterOf(callable, pos) and
54795482
sc1 = TSummaryCtx1Param(p) and
@@ -5708,24 +5711,24 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
57085711

57095712
pragma[nomagic]
57105713
private predicate revPartialPathFlowsThrough(
5711-
ArgumentPosition apos, FlowState state, TRevSummaryCtx1Some sc1, TRevSummaryCtx2Some sc2,
5714+
ArgumentPositionEx apos, FlowState state, TRevSummaryCtx1Some sc1, TRevSummaryCtx2Some sc2,
57125715
TRevSummaryCtx3Some sc3, PartialAccessPath ap
57135716
) {
5714-
exists(PartialPathNodeRev mid, ParamNodeEx p, ParameterPosition ppos |
5717+
exists(PartialPathNodeRev mid, ParamNodeEx p, ParameterPositionEx ppos |
57155718
mid.getNodeEx() = p and
57165719
mid.getState() = state and
57175720
p.getPosition() = ppos and
57185721
sc1 = mid.getSummaryCtx1() and
57195722
sc2 = mid.getSummaryCtx2() and
57205723
sc3 = mid.getSummaryCtx3() and
57215724
ap = mid.getAp() and
5722-
parameterMatch(ppos, apos)
5725+
parameterMatchEx(ppos, apos)
57235726
)
57245727
}
57255728

57265729
pragma[nomagic]
57275730
private predicate revPartialPathThroughCallable0(
5728-
DataFlowCall call, PartialPathNodeRev mid, ArgumentPosition pos, FlowState state,
5731+
DataFlowCall call, PartialPathNodeRev mid, ArgumentPositionEx pos, FlowState state,
57295732
PartialAccessPath ap
57305733
) {
57315734
exists(TRevSummaryCtx1Some sc1, TRevSummaryCtx2Some sc2, TRevSummaryCtx3Some sc3 |
@@ -5738,7 +5741,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
57385741
private predicate revPartialPathThroughCallable(
57395742
PartialPathNodeRev mid, ArgNodeEx node, FlowState state, PartialAccessPath ap
57405743
) {
5741-
exists(DataFlowCall call, ArgumentPosition pos |
5744+
exists(DataFlowCall call, ArgumentPositionEx pos |
57425745
revPartialPathThroughCallable0(call, mid, pos, state, ap) and
57435746
node.argumentOf(call, pos)
57445747
)

0 commit comments

Comments
 (0)