Skip to content

Commit 73b93be

Browse files
committed
C++: Prevent non-termination in 'getTypeImpl' when a iterator defines itself as 'value_type'.
1 parent 526b913 commit 73b93be

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,15 @@ private Type getTypeImpl(Type t, int indirectionIndex) {
670670
result = t
671671
or
672672
indirectionIndex > 0 and
673-
result = getTypeImpl(stripPointer(t), indirectionIndex - 1)
673+
exists(Type stripped |
674+
stripped = stripPointer(t) and
675+
// We need to avoid the case where `stripPointer(t) = t` (which can happen on
676+
// iterators that specify a `value_type` that is the iterator itself). Such a type
677+
// would create an infinite loop otherwise. For these cases we simply don't produce
678+
// a result for `getType`.
679+
stripped.getUnspecifiedType() != t.getUnspecifiedType() and
680+
result = getTypeImpl(stripPointer(t), indirectionIndex - 1)
681+
)
674682
}
675683

676684
/**

0 commit comments

Comments
 (0)