Skip to content

Commit dacd42a

Browse files
committed
C++: Restrict TypeState to reachable tuples.
1 parent 33b8346 commit dacd42a

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,20 +1455,29 @@ module ConstructorForwarding {
14551455
)
14561456
}
14571457

1458-
private predicate typeFwd(TypeState state) {
1459-
state.isSource(_)
1460-
or
1461-
exists(TypeState previous |
1462-
typeFwd(previous) and
1463-
step(previous, state)
1458+
private predicate typeFwd(Type type, ValueCategory category, boolean conversionUsed, Phase phase) {
1459+
not type instanceof Cpp::ReferenceType and
1460+
not type instanceof FunctionReferenceType and
1461+
isUnderlyingType(type) and
1462+
(
1463+
type = getValueType(getForwardedArgumentType(_, _, _), category) and
1464+
conversionUsed = false and
1465+
phase = Initial()
1466+
or
1467+
exists(
1468+
Type previousType, ValueCategory previousCategory, boolean previousConversionUsed,
1469+
Phase previousPhase
1470+
|
1471+
typeFwd(previousType, previousCategory, previousConversionUsed, previousPhase) and
1472+
typeStep(previousType, previousCategory, previousConversionUsed, previousPhase, type,
1473+
category, conversionUsed, phase)
1474+
)
14641475
)
14651476
}
14661477

14671478
private newtype TTypeState =
14681479
MkTypeState(Type type, ValueCategory category, Boolean conversionUsed, Phase phase) {
1469-
not type instanceof Cpp::ReferenceType and
1470-
not type instanceof FunctionReferenceType and
1471-
isUnderlyingType(type)
1480+
typeFwd(type, category, conversionUsed, phase)
14721481
}
14731482

14741483
private class TypeState extends TTypeState {
@@ -1505,14 +1514,11 @@ module ConstructorForwarding {
15051514
}
15061515

15071516
private predicate typeRev(TypeState state, Cpp::Constructor constructor) {
1508-
typeFwd(state) and
1509-
(
1510-
state.isSink(_, constructor)
1511-
or
1512-
exists(TypeState next |
1513-
typeRev(next, constructor) and
1514-
step(state, next)
1515-
)
1517+
state.isSink(_, constructor)
1518+
or
1519+
exists(TypeState next |
1520+
typeRev(next, constructor) and
1521+
step(state, next)
15161522
)
15171523
}
15181524

0 commit comments

Comments
 (0)