Skip to content

Commit 540ecf3

Browse files
committed
Data flow: Sync files
1 parent 755085e commit 540ecf3

33 files changed

+1568
-1374
lines changed

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ private class ArgNodeEx extends NodeEx {
256256
private class ParamNodeEx extends NodeEx {
257257
ParamNodeEx() { this.asNode() instanceof ParamNode }
258258

259-
predicate isParameterOf(DataFlowCallable c, int i) {
260-
this.asNode().(ParamNode).isParameterOf(c, i)
259+
predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
260+
this.asNode().(ParamNode).isParameterOf(c, pos)
261261
}
262262

263-
int getPosition() { this.isParameterOf(_, result) }
263+
ParameterPosition getPosition() { this.isParameterOf(_, result) }
264264

265265
predicate allowParameterReturnInSelf() { allowParameterReturnInSelfCached(this.asNode()) }
266266
}
@@ -1430,7 +1430,7 @@ private module Stage2 {
14301430
}
14311431

14321432
predicate parameterMayFlowThrough(ParamNodeEx p, DataFlowCallable c, Ap ap, Configuration config) {
1433-
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, int pos |
1433+
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, ParameterPosition pos |
14341434
parameterFlow(p, ap, ap0, c, config) and
14351435
c = ret.getEnclosingCallable() and
14361436
revFlow(pragma[only_bind_into](ret), true, apSome(_), pragma[only_bind_into](ap0),
@@ -2125,7 +2125,7 @@ private module Stage3 {
21252125
}
21262126

21272127
predicate parameterMayFlowThrough(ParamNodeEx p, DataFlowCallable c, Ap ap, Configuration config) {
2128-
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, int pos |
2128+
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, ParameterPosition pos |
21292129
parameterFlow(p, ap, ap0, c, config) and
21302130
c = ret.getEnclosingCallable() and
21312131
revFlow(pragma[only_bind_into](ret), true, apSome(_), pragma[only_bind_into](ap0),
@@ -2891,7 +2891,7 @@ private module Stage4 {
28912891
}
28922892

28932893
predicate parameterMayFlowThrough(ParamNodeEx p, DataFlowCallable c, Ap ap, Configuration config) {
2894-
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, int pos |
2894+
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, ParameterPosition pos |
28952895
parameterFlow(p, ap, ap0, c, config) and
28962896
c = ret.getEnclosingCallable() and
28972897
revFlow(pragma[only_bind_into](ret), true, apSome(_), pragma[only_bind_into](ap0),
@@ -2975,7 +2975,7 @@ private class SummaryCtxSome extends SummaryCtx, TSummaryCtxSome {
29752975

29762976
SummaryCtxSome() { this = TSummaryCtxSome(p, ap) }
29772977

2978-
int getParameterPos() { p.isParameterOf(_, result) }
2978+
ParameterPosition getParameterPos() { p.isParameterOf(_, result) }
29792979

29802980
ParamNodeEx getParamNode() { result = p }
29812981

@@ -3622,39 +3622,40 @@ private predicate pathOutOfCallable(PathNodeMid mid, NodeEx out, CallContext cc)
36223622
*/
36233623
pragma[noinline]
36243624
private predicate pathIntoArg(
3625-
PathNodeMid mid, int i, CallContext cc, DataFlowCall call, AccessPath ap, AccessPathApprox apa,
3626-
Configuration config
3625+
PathNodeMid mid, ParameterPosition ppos, CallContext cc, DataFlowCall call, AccessPath ap,
3626+
AccessPathApprox apa, Configuration config
36273627
) {
3628-
exists(ArgNode arg |
3628+
exists(ArgNode arg, ArgumentPosition apos |
36293629
arg = mid.getNodeEx().asNode() and
36303630
cc = mid.getCallContext() and
3631-
arg.argumentOf(call, i) and
3631+
arg.argumentOf(call, apos) and
36323632
ap = mid.getAp() and
36333633
apa = ap.getApprox() and
3634-
config = mid.getConfiguration()
3634+
config = mid.getConfiguration() and
3635+
parameterMatch(ppos, apos)
36353636
)
36363637
}
36373638

36383639
pragma[nomagic]
36393640
private predicate parameterCand(
3640-
DataFlowCallable callable, int i, AccessPathApprox apa, Configuration config
3641+
DataFlowCallable callable, ParameterPosition pos, AccessPathApprox apa, Configuration config
36413642
) {
36423643
exists(ParamNodeEx p |
36433644
Stage4::revFlow(p, _, _, apa, config) and
3644-
p.isParameterOf(callable, i)
3645+
p.isParameterOf(callable, pos)
36453646
)
36463647
}
36473648

36483649
pragma[nomagic]
36493650
private predicate pathIntoCallable0(
3650-
PathNodeMid mid, DataFlowCallable callable, int i, CallContext outercc, DataFlowCall call,
3651-
AccessPath ap, Configuration config
3651+
PathNodeMid mid, DataFlowCallable callable, ParameterPosition pos, CallContext outercc,
3652+
DataFlowCall call, AccessPath ap, Configuration config
36523653
) {
36533654
exists(AccessPathApprox apa |
3654-
pathIntoArg(mid, pragma[only_bind_into](i), outercc, call, ap, pragma[only_bind_into](apa),
3655+
pathIntoArg(mid, pragma[only_bind_into](pos), outercc, call, ap, pragma[only_bind_into](apa),
36553656
pragma[only_bind_into](config)) and
36563657
callable = resolveCall(call, outercc) and
3657-
parameterCand(callable, pragma[only_bind_into](i), pragma[only_bind_into](apa),
3658+
parameterCand(callable, pragma[only_bind_into](pos), pragma[only_bind_into](apa),
36583659
pragma[only_bind_into](config))
36593660
)
36603661
}
@@ -3669,9 +3670,9 @@ private predicate pathIntoCallable(
36693670
PathNodeMid mid, ParamNodeEx p, CallContext outercc, CallContextCall innercc, SummaryCtx sc,
36703671
DataFlowCall call, Configuration config
36713672
) {
3672-
exists(int i, DataFlowCallable callable, AccessPath ap |
3673-
pathIntoCallable0(mid, callable, i, outercc, call, ap, config) and
3674-
p.isParameterOf(callable, i) and
3673+
exists(ParameterPosition pos, DataFlowCallable callable, AccessPath ap |
3674+
pathIntoCallable0(mid, callable, pos, outercc, call, ap, config) and
3675+
p.isParameterOf(callable, pos) and
36753676
(
36763677
sc = TSummaryCtxSome(p, ap)
36773678
or
@@ -3695,7 +3696,7 @@ private predicate paramFlowsThrough(
36953696
ReturnKindExt kind, CallContextCall cc, SummaryCtxSome sc, AccessPath ap, AccessPathApprox apa,
36963697
Configuration config
36973698
) {
3698-
exists(PathNodeMid mid, RetNodeEx ret, int pos |
3699+
exists(PathNodeMid mid, RetNodeEx ret, ParameterPosition pos |
36993700
mid.getNodeEx() = ret and
37003701
kind = ret.getKind() and
37013702
cc = mid.getCallContext() and
@@ -4424,24 +4425,25 @@ private module FlowExploration {
44244425

44254426
pragma[noinline]
44264427
private predicate partialPathIntoArg(
4427-
PartialPathNodeFwd mid, int i, CallContext cc, DataFlowCall call, PartialAccessPath ap,
4428-
Configuration config
4428+
PartialPathNodeFwd mid, ParameterPosition ppos, CallContext cc, DataFlowCall call,
4429+
PartialAccessPath ap, Configuration config
44294430
) {
4430-
exists(ArgNode arg |
4431+
exists(ArgNode arg, ArgumentPosition apos |
44314432
arg = mid.getNodeEx().asNode() and
44324433
cc = mid.getCallContext() and
4433-
arg.argumentOf(call, i) and
4434+
arg.argumentOf(call, apos) and
44344435
ap = mid.getAp() and
4435-
config = mid.getConfiguration()
4436+
config = mid.getConfiguration() and
4437+
parameterMatch(ppos, apos)
44364438
)
44374439
}
44384440

44394441
pragma[nomagic]
44404442
private predicate partialPathIntoCallable0(
4441-
PartialPathNodeFwd mid, DataFlowCallable callable, int i, CallContext outercc,
4443+
PartialPathNodeFwd mid, DataFlowCallable callable, ParameterPosition pos, CallContext outercc,
44424444
DataFlowCall call, PartialAccessPath ap, Configuration config
44434445
) {
4444-
partialPathIntoArg(mid, i, outercc, call, ap, config) and
4446+
partialPathIntoArg(mid, pos, outercc, call, ap, config) and
44454447
callable = resolveCall(call, outercc)
44464448
}
44474449

@@ -4450,9 +4452,9 @@ private module FlowExploration {
44504452
TSummaryCtx1 sc1, TSummaryCtx2 sc2, DataFlowCall call, PartialAccessPath ap,
44514453
Configuration config
44524454
) {
4453-
exists(int i, DataFlowCallable callable |
4454-
partialPathIntoCallable0(mid, callable, i, outercc, call, ap, config) and
4455-
p.isParameterOf(callable, i) and
4455+
exists(ParameterPosition pos, DataFlowCallable callable |
4456+
partialPathIntoCallable0(mid, callable, pos, outercc, call, ap, config) and
4457+
p.isParameterOf(callable, pos) and
44564458
sc1 = TSummaryCtx1Param(p) and
44574459
sc2 = TSummaryCtx2Some(ap)
44584460
|
@@ -4616,22 +4618,23 @@ private module FlowExploration {
46164618

46174619
pragma[nomagic]
46184620
private predicate revPartialPathFlowsThrough(
4619-
int pos, TRevSummaryCtx1Some sc1, TRevSummaryCtx2Some sc2, RevPartialAccessPath ap,
4620-
Configuration config
4621+
ArgumentPosition apos, TRevSummaryCtx1Some sc1, TRevSummaryCtx2Some sc2,
4622+
RevPartialAccessPath ap, Configuration config
46214623
) {
4622-
exists(PartialPathNodeRev mid, ParamNodeEx p |
4624+
exists(PartialPathNodeRev mid, ParamNodeEx p, ParameterPosition ppos |
46234625
mid.getNodeEx() = p and
4624-
p.getPosition() = pos and
4626+
p.getPosition() = ppos and
46254627
sc1 = mid.getSummaryCtx1() and
46264628
sc2 = mid.getSummaryCtx2() and
46274629
ap = mid.getAp() and
4628-
config = mid.getConfiguration()
4630+
config = mid.getConfiguration() and
4631+
parameterMatch(ppos, apos)
46294632
)
46304633
}
46314634

46324635
pragma[nomagic]
46334636
private predicate revPartialPathThroughCallable0(
4634-
DataFlowCall call, PartialPathNodeRev mid, int pos, RevPartialAccessPath ap,
4637+
DataFlowCall call, PartialPathNodeRev mid, ArgumentPosition pos, RevPartialAccessPath ap,
46354638
Configuration config
46364639
) {
46374640
exists(TRevSummaryCtx1Some sc1, TRevSummaryCtx2Some sc2 |
@@ -4644,7 +4647,7 @@ private module FlowExploration {
46444647
private predicate revPartialPathThroughCallable(
46454648
PartialPathNodeRev mid, ArgNodeEx node, RevPartialAccessPath ap, Configuration config
46464649
) {
4647-
exists(DataFlowCall call, int pos |
4650+
exists(DataFlowCall call, ArgumentPosition pos |
46484651
revPartialPathThroughCallable0(call, mid, pos, ap, config) and
46494652
node.asNode().(ArgNode).argumentOf(call, pos)
46504653
)

0 commit comments

Comments
 (0)