Skip to content

Commit cf84a53

Browse files
committed
Java/C++/C#: Fix bug in type pruning.
1 parent 02ae0fb commit cf84a53

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

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

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,33 +1307,39 @@ private predicate localFlowExit(Node node, Configuration config) {
13071307
*/
13081308
pragma[nomagic]
13091309
private predicate localFlowStepPlus(
1310-
Node node1, Node node2, boolean preservesValue, Configuration config, LocalCallContext cc
1310+
Node node1, Node node2, boolean preservesValue, DataFlowType t, Configuration config,
1311+
LocalCallContext cc
13111312
) {
13121313
not isUnreachableInCall(node2, cc.(LocalCallContextSpecificCall).getCall()) and
13131314
(
13141315
localFlowEntry(node1, config) and
13151316
(
1316-
localFlowStep(node1, node2, config) and preservesValue = true
1317+
localFlowStep(node1, node2, config) and
1318+
preservesValue = true and
1319+
t = getErasedNodeTypeBound(node1)
13171320
or
1318-
additionalLocalFlowStep(node1, node2, config) and preservesValue = false
1321+
additionalLocalFlowStep(node1, node2, config) and
1322+
preservesValue = false and
1323+
t = getErasedNodeTypeBound(node2)
13191324
) and
13201325
node1 != node2 and
13211326
cc.relevantFor(node1.getEnclosingCallable()) and
13221327
not isUnreachableInCall(node1, cc.(LocalCallContextSpecificCall).getCall()) and
13231328
nodeCand(TNormalNode(node2), unbind(config))
13241329
or
13251330
exists(Node mid |
1326-
localFlowStepPlus(node1, mid, preservesValue, config, cc) and
1331+
localFlowStepPlus(node1, mid, preservesValue, t, config, cc) and
13271332
localFlowStep(mid, node2, config) and
13281333
not mid instanceof CastNode and
13291334
nodeCand(TNormalNode(node2), unbind(config))
13301335
)
13311336
or
13321337
exists(Node mid |
1333-
localFlowStepPlus(node1, mid, _, config, cc) and
1338+
localFlowStepPlus(node1, mid, _, _, config, cc) and
13341339
additionalLocalFlowStep(mid, node2, config) and
13351340
not mid instanceof CastNode and
13361341
preservesValue = false and
1342+
t = getErasedNodeTypeBound(node2) and
13371343
nodeCand(TNormalNode(node2), unbind(config))
13381344
)
13391345
)
@@ -1345,17 +1351,18 @@ private predicate localFlowStepPlus(
13451351
*/
13461352
pragma[nomagic]
13471353
private predicate localFlowBigStep(
1348-
Node node1, Node node2, boolean preservesValue, Configuration config, LocalCallContext callContext
1354+
Node node1, Node node2, boolean preservesValue, DataFlowType t, Configuration config,
1355+
LocalCallContext callContext
13491356
) {
1350-
localFlowStepPlus(node1, node2, preservesValue, config, callContext) and
1357+
localFlowStepPlus(node1, node2, preservesValue, t, config, callContext) and
13511358
localFlowExit(node2, config)
13521359
}
13531360

13541361
pragma[nomagic]
13551362
private predicate localFlowBigStepExt(
1356-
NodeExt node1, NodeExt node2, boolean preservesValue, Configuration config
1363+
NodeExt node1, NodeExt node2, boolean preservesValue, AccessPathFrontNil apf, Configuration config
13571364
) {
1358-
localFlowBigStep(node1.getNode(), node2.getNode(), preservesValue, config, _)
1365+
localFlowBigStep(node1.getNode(), node2.getNode(), preservesValue, apf.getType(), config, _)
13591366
}
13601367

13611368
private newtype TAccessPathFront =
@@ -1406,8 +1413,6 @@ private class AccessPathFrontNilNode extends NormalNodeExt {
14061413
(
14071414
any(Configuration c).isSource(this.getNode())
14081415
or
1409-
localFlowBigStepExt(_, this, false, _)
1410-
or
14111416
additionalJumpStepExt(_, this, _)
14121417
)
14131418
}
@@ -1428,13 +1433,12 @@ private predicate flowCandFwd0(
14281433
(
14291434
exists(NodeExt mid |
14301435
flowCandFwd(mid, fromArg, apf, config) and
1431-
localFlowBigStepExt(mid, node, true, config)
1436+
localFlowBigStepExt(mid, node, true, _, config)
14321437
)
14331438
or
14341439
exists(NodeExt mid, AccessPathFrontNil nil |
14351440
flowCandFwd(mid, fromArg, nil, config) and
1436-
localFlowBigStepExt(mid, node, false, config) and
1437-
apf = node.(AccessPathFrontNilNode).getApf()
1441+
localFlowBigStepExt(mid, node, false, apf, config)
14381442
)
14391443
or
14401444
exists(NodeExt mid |
@@ -1589,13 +1593,13 @@ private predicate flowCand0(
15891593
apf instanceof AccessPathFrontNil
15901594
or
15911595
exists(NodeExt mid |
1592-
localFlowBigStepExt(node, mid, true, config) and
1596+
localFlowBigStepExt(node, mid, true, _, config) and
15931597
flowCand(mid, toReturn, apf, config)
15941598
)
15951599
or
15961600
exists(NodeExt mid, AccessPathFrontNil nil |
15971601
flowCandFwd(node, _, apf, config) and
1598-
localFlowBigStepExt(node, mid, false, config) and
1602+
localFlowBigStepExt(node, mid, false, _, config) and
15991603
flowCand(mid, toReturn, nil, config) and
16001604
apf instanceof AccessPathFrontNil
16011605
)
@@ -1845,13 +1849,12 @@ private predicate flowFwd0(
18451849
(
18461850
exists(NodeExt mid |
18471851
flowFwd(mid, fromArg, apf, ap, config) and
1848-
localFlowBigStepExt(mid, node, true, config)
1852+
localFlowBigStepExt(mid, node, true, _, config)
18491853
)
18501854
or
18511855
exists(NodeExt mid, AccessPathNil nil |
18521856
flowFwd(mid, fromArg, _, nil, config) and
1853-
localFlowBigStepExt(mid, node, false, config) and
1854-
ap = node.(AccessPathNilNode).getAp() and
1857+
localFlowBigStepExt(mid, node, false, apf, config) and
18551858
apf = ap.(AccessPathNil).getFront()
18561859
)
18571860
or
@@ -1982,13 +1985,13 @@ private predicate flow0(NodeExt node, boolean toReturn, AccessPath ap, Configura
19821985
ap instanceof AccessPathNil
19831986
or
19841987
exists(NodeExt mid |
1985-
localFlowBigStepExt(node, mid, true, config) and
1988+
localFlowBigStepExt(node, mid, true, _, config) and
19861989
flow(mid, toReturn, ap, config)
19871990
)
19881991
or
19891992
exists(NodeExt mid, AccessPathNil nil |
19901993
flowFwd(node, _, _, ap, config) and
1991-
localFlowBigStepExt(node, mid, false, config) and
1994+
localFlowBigStepExt(node, mid, false, _, config) and
19921995
flow(mid, toReturn, nil, config) and
19931996
ap instanceof AccessPathNil
19941997
)
@@ -2357,12 +2360,11 @@ private predicate pathStep(PathNodeMid mid, Node node, CallContext cc, SummaryCt
23572360
pathIntoLocalStep(mid, midnode, cc, enclosing, sc, ap0, conf) and
23582361
localCC = getLocalCallContext(cc, enclosing)
23592362
|
2360-
localFlowBigStep(midnode, node, true, conf, localCC) and
2363+
localFlowBigStep(midnode, node, true, _, conf, localCC) and
23612364
ap = ap0
23622365
or
2363-
localFlowBigStep(midnode, node, false, conf, localCC) and
2364-
ap0 instanceof AccessPathNil and
2365-
ap = any(AccessPathNilNode nil | nil.getNode() = node).getAp()
2366+
localFlowBigStep(midnode, node, false, ap.(AccessPathNil).getType(), conf, localCC) and
2367+
ap0 instanceof AccessPathNil
23662368
)
23672369
or
23682370
jumpStep(mid.getNode(), node, mid.getConfiguration()) and
@@ -2397,7 +2399,7 @@ private predicate pathIntoLocalStep(
23972399
midnode = mid.getNode() and
23982400
cc = mid.getCallContext() and
23992401
conf = mid.getConfiguration() and
2400-
localFlowBigStep(midnode, _, _, conf, _) and
2402+
localFlowBigStep(midnode, _, _, _, conf, _) and
24012403
enclosing = midnode.getEnclosingCallable() and
24022404
sc = mid.getSummaryCtx() and
24032405
ap0 = mid.getAp()

0 commit comments

Comments
 (0)