Skip to content

Commit fdf6e30

Browse files
committed
Dataflow: Handle non-trivial type systems with stores into a top type.
1 parent a26132e commit fdf6e30

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,11 +1448,21 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
14481448
private predicate compatibleContainer0(ApHeadContent apc, DataFlowType containerType) {
14491449
exists(DataFlowType containerType0, Content c |
14501450
PrevStage::storeStepCand(_, _, c, _, _, containerType0) and
1451+
not isTopType(containerType0) and
14511452
compatibleTypesCached(containerType0, containerType) and
14521453
apc = projectToHeadContent(c)
14531454
)
14541455
}
14551456

1457+
pragma[nomagic]
1458+
private predicate topTypeContent(ApHeadContent apc) {
1459+
exists(DataFlowType containerType0, Content c |
1460+
PrevStage::storeStepCand(_, _, c, _, _, containerType0) and
1461+
isTopType(containerType0) and
1462+
apc = projectToHeadContent(c)
1463+
)
1464+
}
1465+
14561466
bindingset[apc, containerType]
14571467
pragma[inline_late]
14581468
private predicate compatibleContainer(ApHeadContent apc, DataFlowType containerType) {
@@ -1484,7 +1494,9 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
14841494
(
14851495
if castingNodeEx(node)
14861496
then
1487-
ap instanceof ApNil or compatibleContainer(getHeadContent(ap), node.getDataFlowType())
1497+
ap instanceof ApNil or
1498+
compatibleContainer(getHeadContent(ap), node.getDataFlowType()) or
1499+
topTypeContent(getHeadContent(ap))
14881500
else any()
14891501
)
14901502
}

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,14 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
889889
cached
890890
predicate compatibleTypesCached(DataFlowType t1, DataFlowType t2) { compatibleTypes(t1, t2) }
891891

892+
private predicate relevantType(DataFlowType t) { t = getNodeType(_) }
893+
894+
cached
895+
predicate isTopType(DataFlowType t) {
896+
strictcount(DataFlowType t0 | relevantType(t0)) =
897+
strictcount(DataFlowType t0 | relevantType(t0) and compatibleTypesCached(t, t0))
898+
}
899+
892900
cached
893901
predicate typeStrongerThanCached(DataFlowType t1, DataFlowType t2) { typeStrongerThan(t1, t2) }
894902

0 commit comments

Comments
 (0)