Skip to content

Commit 1c1d11a

Browse files
committed
DataFlow: Address review comments.
1 parent 6374914 commit 1c1d11a

File tree

1 file changed

+58
-56
lines changed

1 file changed

+58
-56
lines changed

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImpl.qll

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ abstract private class ConfigurationRecursionPrevention extends Configuration {
190190

191191
private newtype TNodeEx =
192192
TNodeNormal(Node n) or
193-
TNodeImplicitRead(Node n, boolean b) {
194-
any(Configuration c).allowImplicitRead(n, _) and b = [false, true]
193+
TNodeImplicitRead(Node n, boolean hasRead) {
194+
any(Configuration c).allowImplicitRead(n, _) and hasRead = [false, true]
195195
}
196196

197197
private class NodeEx extends TNodeEx {
@@ -203,12 +203,27 @@ private class NodeEx extends TNodeEx {
203203

204204
Node asNode() { this = TNodeNormal(result) }
205205

206-
predicate isImplicitReadNode(Node n, boolean b) { this = TNodeImplicitRead(n, b) }
206+
predicate isImplicitReadNode(Node n, boolean hasRead) { this = TNodeImplicitRead(n, hasRead) }
207207

208208
Node projectToNode() { this = TNodeNormal(result) or this = TNodeImplicitRead(result, _) }
209209

210210
pragma[nomagic]
211-
DataFlowCallable getEnclosingCallable() { nodeEnclosingCallable(this.projectToNode(), result) }
211+
private DataFlowCallable getEnclosingCallable0() {
212+
nodeEnclosingCallable(this.projectToNode(), result)
213+
}
214+
215+
pragma[inline]
216+
DataFlowCallable getEnclosingCallable() {
217+
pragma[only_bind_out](this).getEnclosingCallable0() = pragma[only_bind_into](result)
218+
}
219+
220+
pragma[nomagic]
221+
private DataFlowType getDataFlowType0() { nodeDataFlowType(this.asNode(), result) }
222+
223+
pragma[inline]
224+
DataFlowType getDataFlowType() {
225+
pragma[only_bind_out](this).getDataFlowType0() = pragma[only_bind_into](result)
226+
}
212227

213228
predicate hasLocationInfo(
214229
string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -239,19 +254,6 @@ private class RetNodeEx extends NodeEx {
239254
ReturnKindExt getKind() { result = this.asNode().(ReturnNodeExt).getKind() }
240255
}
241256

242-
pragma[inline]
243-
private DataFlowCallable getEnclosingCallable(NodeEx n) {
244-
pragma[only_bind_out](n).getEnclosingCallable() = pragma[only_bind_into](result)
245-
}
246-
247-
pragma[nomagic]
248-
private DataFlowType getDataFlowType0(NodeEx n) { nodeDataFlowType(n.asNode(), result) }
249-
250-
pragma[inline]
251-
private DataFlowType getDataFlowType(NodeEx n) {
252-
getDataFlowType0(pragma[only_bind_out](n)) = pragma[only_bind_into](result)
253-
}
254-
255257
private predicate inBarrier(NodeEx node, Configuration config) {
256258
exists(Node n |
257259
node.asNode() = n and
@@ -727,7 +729,7 @@ private module Stage1 {
727729
) {
728730
exists(RetNodeEx ret |
729731
throughFlowNodeCand(ret, config) and
730-
callable = getEnclosingCallable(ret) and
732+
callable = ret.getEnclosingCallable() and
731733
kind = ret.getKind()
732734
)
733735
}
@@ -740,7 +742,7 @@ private module Stage1 {
740742
exists(ReturnKindExt kind |
741743
throughFlowNodeCand(p, config) and
742744
returnFlowCallableNodeCand(c, kind, config) and
743-
getEnclosingCallable(p) = c and
745+
p.getEnclosingCallable() = c and
744746
exists(ap) and
745747
// we don't expect a parameter to return stored in itself
746748
not kind.(ParamUpdateReturnKind).getPosition() = p.getPosition()
@@ -984,7 +986,7 @@ private module Stage2 {
984986
) {
985987
flowOutOfCall(call, ret, out, allowsFieldFlow, pragma[only_bind_into](config)) and
986988
PrevStage::callMayFlowThroughRev(call, pragma[only_bind_into](config)) and
987-
PrevStage::parameterMayFlowThrough(_, getEnclosingCallable(ret), _,
989+
PrevStage::parameterMayFlowThrough(_, ret.getEnclosingCallable(), _,
988990
pragma[only_bind_into](config))
989991
}
990992

@@ -1103,7 +1105,7 @@ private module Stage2 {
11031105
exists(ArgNodeEx arg, boolean allowsFieldFlow |
11041106
fwdFlow(arg, outercc, argAp, ap, config) and
11051107
flowIntoCall(call, arg, p, allowsFieldFlow, config) and
1106-
innercc = getCallContextCall(call, getEnclosingCallable(p), outercc)
1108+
innercc = getCallContextCall(call, p.getEnclosingCallable(), outercc)
11071109
|
11081110
ap instanceof ApNil or allowsFieldFlow = true
11091111
)
@@ -1119,7 +1121,7 @@ private module Stage2 {
11191121
|
11201122
fwdFlow(ret, innercc, argAp, ap, config) and
11211123
flowOutOfCall(call, ret, out, allowsFieldFlow, config) and
1122-
inner = getEnclosingCallable(ret) and
1124+
inner = ret.getEnclosingCallable() and
11231125
checkCallContextReturn(innercc, inner, call) and
11241126
ccOut = getCallContextReturn(inner, call)
11251127
|
@@ -1384,13 +1386,13 @@ private module Stage2 {
13841386
ParamNodeEx p, Ap ap, Ap ap0, DataFlowCallable c, Configuration config
13851387
) {
13861388
revFlow(p, true, apSome(ap0), ap, config) and
1387-
c = getEnclosingCallable(p)
1389+
c = p.getEnclosingCallable()
13881390
}
13891391

13901392
predicate parameterMayFlowThrough(ParamNodeEx p, DataFlowCallable c, Ap ap, Configuration config) {
13911393
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, int pos |
13921394
parameterFlow(p, ap, ap0, c, config) and
1393-
c = getEnclosingCallable(ret) and
1395+
c = ret.getEnclosingCallable() and
13941396
revFlow(ret, true, apSome(_), ap0, config) and
13951397
fwdFlow(ret, any(CcCall ccc), apSome(ap), ap0, config) and
13961398
kind = ret.getKind() and
@@ -1520,14 +1522,14 @@ private module LocalFlowBigStep {
15201522
(
15211523
localFlowStepNodeCand1(node1, node2, config) and
15221524
preservesValue = true and
1523-
t = getDataFlowType(node1) // irrelevant dummy value
1525+
t = node1.getDataFlowType() // irrelevant dummy value
15241526
or
15251527
additionalLocalFlowStepNodeCand2(node1, node2, config) and
15261528
preservesValue = false and
1527-
t = getDataFlowType(node2)
1529+
t = node2.getDataFlowType()
15281530
) and
15291531
node1 != node2 and
1530-
cc.relevantFor(getEnclosingCallable(node1)) and
1532+
cc.relevantFor(node1.getEnclosingCallable()) and
15311533
not isUnreachableInCallCached(node1.asNode(), cc.(LocalCallContextSpecificCall).getCall()) and
15321534
Stage2::revFlow(node2, pragma[only_bind_into](config))
15331535
or
@@ -1543,7 +1545,7 @@ private module LocalFlowBigStep {
15431545
additionalLocalFlowStepNodeCand2(mid, node2, config) and
15441546
not mid instanceof FlowCheckNode and
15451547
preservesValue = false and
1546-
t = getDataFlowType(node2) and
1548+
t = node2.getDataFlowType() and
15471549
Stage2::revFlow(node2, pragma[only_bind_into](config))
15481550
)
15491551
)
@@ -1577,7 +1579,7 @@ private module Stage3 {
15771579
private ApApprox getApprox(Ap ap) { result = ap.toBoolNonEmpty() }
15781580

15791581
private ApNil getApNil(NodeEx node) {
1580-
PrevStage::revFlow(node, _) and result = TFrontNil(getDataFlowType(node))
1582+
PrevStage::revFlow(node, _) and result = TFrontNil(node.getDataFlowType())
15811583
}
15821584

15831585
bindingset[tc, tail]
@@ -1642,7 +1644,7 @@ private module Stage3 {
16421644
bindingset[node, ap]
16431645
private predicate filter(NodeEx node, Ap ap) {
16441646
not clear(node, ap) and
1645-
if castingNodeEx(node) then compatibleTypes(getDataFlowType(node), ap.getType()) else any()
1647+
if castingNodeEx(node) then compatibleTypes(node.getDataFlowType(), ap.getType()) else any()
16461648
}
16471649

16481650
bindingset[ap, contentType]
@@ -1670,7 +1672,7 @@ private module Stage3 {
16701672
) {
16711673
flowOutOfCall(call, ret, out, allowsFieldFlow, pragma[only_bind_into](config)) and
16721674
PrevStage::callMayFlowThroughRev(call, pragma[only_bind_into](config)) and
1673-
PrevStage::parameterMayFlowThrough(_, getEnclosingCallable(ret), _,
1675+
PrevStage::parameterMayFlowThrough(_, ret.getEnclosingCallable(), _,
16741676
pragma[only_bind_into](config))
16751677
}
16761678

@@ -1796,7 +1798,7 @@ private module Stage3 {
17961798
exists(ArgNodeEx arg, boolean allowsFieldFlow |
17971799
fwdFlow(arg, outercc, argAp, ap, config) and
17981800
flowIntoCall(call, arg, p, allowsFieldFlow, config) and
1799-
innercc = getCallContextCall(call, getEnclosingCallable(p), outercc)
1801+
innercc = getCallContextCall(call, p.getEnclosingCallable(), outercc)
18001802
|
18011803
ap instanceof ApNil or allowsFieldFlow = true
18021804
)
@@ -1812,7 +1814,7 @@ private module Stage3 {
18121814
|
18131815
fwdFlow(ret, innercc, argAp, ap, config) and
18141816
flowOutOfCall(call, ret, out, allowsFieldFlow, config) and
1815-
inner = getEnclosingCallable(ret) and
1817+
inner = ret.getEnclosingCallable() and
18161818
checkCallContextReturn(innercc, inner, call) and
18171819
ccOut = getCallContextReturn(inner, call)
18181820
|
@@ -2077,13 +2079,13 @@ private module Stage3 {
20772079
ParamNodeEx p, Ap ap, Ap ap0, DataFlowCallable c, Configuration config
20782080
) {
20792081
revFlow(p, true, apSome(ap0), ap, config) and
2080-
c = getEnclosingCallable(p)
2082+
c = p.getEnclosingCallable()
20812083
}
20822084

20832085
predicate parameterMayFlowThrough(ParamNodeEx p, DataFlowCallable c, Ap ap, Configuration config) {
20842086
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, int pos |
20852087
parameterFlow(p, ap, ap0, c, config) and
2086-
c = getEnclosingCallable(ret) and
2088+
c = ret.getEnclosingCallable() and
20872089
revFlow(ret, true, apSome(_), ap0, config) and
20882090
fwdFlow(ret, any(CcCall ccc), apSome(ap), ap0, config) and
20892091
kind = ret.getKind() and
@@ -2333,7 +2335,7 @@ private module Stage4 {
23332335
private ApApprox getApprox(Ap ap) { result = ap.getFront() }
23342336

23352337
private ApNil getApNil(NodeEx node) {
2336-
PrevStage::revFlow(node, _) and result = TNil(getDataFlowType(node))
2338+
PrevStage::revFlow(node, _) and result = TNil(node.getDataFlowType())
23372339
}
23382340

23392341
bindingset[tc, tail]
@@ -2379,7 +2381,7 @@ private module Stage4 {
23792381
localFlowEntry(node, config) and
23802382
result =
23812383
getLocalCallContext(pragma[only_bind_into](pragma[only_bind_out](cc)),
2382-
getEnclosingCallable(node))
2384+
node.getEnclosingCallable())
23832385
}
23842386

23852387
private predicate localStep(
@@ -2432,7 +2434,7 @@ private module Stage4 {
24322434
) {
24332435
flowOutOfCall(call, ret, out, allowsFieldFlow, pragma[only_bind_into](config)) and
24342436
PrevStage::callMayFlowThroughRev(call, pragma[only_bind_into](config)) and
2435-
PrevStage::parameterMayFlowThrough(_, getEnclosingCallable(ret), _,
2437+
PrevStage::parameterMayFlowThrough(_, ret.getEnclosingCallable(), _,
24362438
pragma[only_bind_into](config))
24372439
}
24382440

@@ -2558,7 +2560,7 @@ private module Stage4 {
25582560
exists(ArgNodeEx arg, boolean allowsFieldFlow |
25592561
fwdFlow(arg, outercc, argAp, ap, config) and
25602562
flowIntoCall(call, arg, p, allowsFieldFlow, config) and
2561-
innercc = getCallContextCall(call, getEnclosingCallable(p), outercc)
2563+
innercc = getCallContextCall(call, p.getEnclosingCallable(), outercc)
25622564
|
25632565
ap instanceof ApNil or allowsFieldFlow = true
25642566
)
@@ -2574,7 +2576,7 @@ private module Stage4 {
25742576
|
25752577
fwdFlow(ret, innercc, argAp, ap, config) and
25762578
flowOutOfCall(call, ret, out, allowsFieldFlow, config) and
2577-
inner = getEnclosingCallable(ret) and
2579+
inner = ret.getEnclosingCallable() and
25782580
checkCallContextReturn(innercc, inner, call) and
25792581
ccOut = getCallContextReturn(inner, call)
25802582
|
@@ -2839,13 +2841,13 @@ private module Stage4 {
28392841
ParamNodeEx p, Ap ap, Ap ap0, DataFlowCallable c, Configuration config
28402842
) {
28412843
revFlow(p, true, apSome(ap0), ap, config) and
2842-
c = getEnclosingCallable(p)
2844+
c = p.getEnclosingCallable()
28432845
}
28442846

28452847
predicate parameterMayFlowThrough(ParamNodeEx p, DataFlowCallable c, Ap ap, Configuration config) {
28462848
exists(RetNodeEx ret, Ap ap0, ReturnKindExt kind, int pos |
28472849
parameterFlow(p, ap, ap0, c, config) and
2848-
c = getEnclosingCallable(ret) and
2850+
c = ret.getEnclosingCallable() and
28492851
revFlow(ret, true, apSome(_), ap0, config) and
28502852
fwdFlow(ret, any(CcCall ccc), apSome(ap), ap0, config) and
28512853
kind = ret.getKind() and
@@ -2890,7 +2892,7 @@ private predicate nodeMayUseSummary(NodeEx n, AccessPathApprox apa, Configuratio
28902892
Stage4::parameterMayFlowThrough(_, c, apa, _) and
28912893
Stage4::revFlow(n, true, _, apa0, config) and
28922894
Stage4::fwdFlow(n, any(CallContextCall ccc), TAccessPathApproxSome(apa), apa0, config) and
2893-
getEnclosingCallable(n) = c
2895+
n.getEnclosingCallable() = c
28942896
)
28952897
}
28962898

@@ -3050,7 +3052,7 @@ private newtype TPathNode =
30503052
sourceNode(node, config) and
30513053
cc instanceof CallContextAny and
30523054
sc instanceof SummaryCtxNone and
3053-
ap = TAccessPathNil(getDataFlowType(node))
3055+
ap = TAccessPathNil(node.getDataFlowType())
30543056
or
30553057
// ... or a step from an existing PathNode to another node.
30563058
exists(PathNodeMid mid |
@@ -3430,7 +3432,7 @@ private predicate pathStep(
34303432
sc = mid.getSummaryCtx() and
34313433
localCC =
34323434
getLocalCallContext(pragma[only_bind_into](pragma[only_bind_out](cc)),
3433-
getEnclosingCallable(midnode)) and
3435+
midnode.getEnclosingCallable()) and
34343436
ap0 = mid.getAp()
34353437
|
34363438
localFlowBigStep(midnode, node, true, _, conf, localCC) and
@@ -3449,7 +3451,7 @@ private predicate pathStep(
34493451
cc instanceof CallContextAny and
34503452
sc instanceof SummaryCtxNone and
34513453
mid.getAp() instanceof AccessPathNil and
3452-
ap = TAccessPathNil(getDataFlowType(node))
3454+
ap = TAccessPathNil(node.getDataFlowType())
34533455
or
34543456
exists(TypedContent tc | pathStoreStep(mid, node, ap.pop(tc), tc, cc)) and
34553457
sc = mid.getSummaryCtx()
@@ -3716,8 +3718,8 @@ private module FlowExploration {
37163718
// flow out of a callable
37173719
viableReturnPosOutEx(_, node1.(RetNodeEx).getReturnPosition(), node2)
37183720
|
3719-
c1 = getEnclosingCallable(node1) and
3720-
c2 = getEnclosingCallable(node2) and
3721+
c1 = node1.getEnclosingCallable() and
3722+
c2 = node2.getEnclosingCallable() and
37213723
c1 != c2
37223724
)
37233725
}
@@ -3892,12 +3894,12 @@ private module FlowExploration {
38923894
cc instanceof CallContextAny and
38933895
sc1 = TSummaryCtx1None() and
38943896
sc2 = TSummaryCtx2None() and
3895-
ap = TPartialNil(getDataFlowType(node)) and
3897+
ap = TPartialNil(node.getDataFlowType()) and
38963898
not fullBarrier(node, config) and
38973899
exists(config.explorationLimit())
38983900
or
38993901
partialPathNodeMk0(node, cc, sc1, sc2, ap, config) and
3900-
distSrc(getEnclosingCallable(node), config) <= config.explorationLimit()
3902+
distSrc(node.getEnclosingCallable(), config) <= config.explorationLimit()
39013903
} or
39023904
TPartialPathNodeRev(
39033905
NodeEx node, TRevSummaryCtx1 sc1, TRevSummaryCtx2 sc2, RevPartialAccessPath ap,
@@ -3914,7 +3916,7 @@ private module FlowExploration {
39143916
revPartialPathStep(mid, node, sc1, sc2, ap, config) and
39153917
not clearsContentCached(node.asNode(), ap.getHead()) and
39163918
not fullBarrier(node, config) and
3917-
distSink(getEnclosingCallable(node), config) <= config.explorationLimit()
3919+
distSink(node.getEnclosingCallable(), config) <= config.explorationLimit()
39183920
)
39193921
}
39203922

@@ -3928,7 +3930,7 @@ private module FlowExploration {
39283930
not fullBarrier(node, config) and
39293931
not clearsContentCached(node.asNode(), ap.getHead().getContent()) and
39303932
if node.asNode() instanceof CastingNode
3931-
then compatibleTypes(getDataFlowType(node), ap.getType())
3933+
then compatibleTypes(node.getDataFlowType(), ap.getType())
39323934
else any()
39333935
)
39343936
}
@@ -3980,15 +3982,15 @@ private module FlowExploration {
39803982
* of interprocedural steps.
39813983
*/
39823984
int getSourceDistance() {
3983-
result = distSrc(getEnclosingCallable(this.getNodeEx()), this.getConfiguration())
3985+
result = distSrc(this.getNodeEx().getEnclosingCallable(), this.getConfiguration())
39843986
}
39853987

39863988
/**
39873989
* Gets the approximate distance to the nearest sink measured in number
39883990
* of interprocedural steps.
39893991
*/
39903992
int getSinkDistance() {
3991-
result = distSink(getEnclosingCallable(this.getNodeEx()), this.getConfiguration())
3993+
result = distSink(this.getNodeEx().getEnclosingCallable(), this.getConfiguration())
39923994
}
39933995

39943996
private string ppAp() {
@@ -4105,7 +4107,7 @@ private module FlowExploration {
41054107
sc1 = mid.getSummaryCtx1() and
41064108
sc2 = mid.getSummaryCtx2() and
41074109
mid.getAp() instanceof PartialAccessPathNil and
4108-
ap = TPartialNil(getDataFlowType(node)) and
4110+
ap = TPartialNil(node.getDataFlowType()) and
41094111
config = mid.getConfiguration()
41104112
)
41114113
or
@@ -4121,7 +4123,7 @@ private module FlowExploration {
41214123
sc1 = TSummaryCtx1None() and
41224124
sc2 = TSummaryCtx2None() and
41234125
mid.getAp() instanceof PartialAccessPathNil and
4124-
ap = TPartialNil(getDataFlowType(node)) and
4126+
ap = TPartialNil(node.getDataFlowType()) and
41254127
config = mid.getConfiguration()
41264128
or
41274129
partialPathStoreStep(mid, _, _, node, ap) and

0 commit comments

Comments
 (0)