Skip to content

Commit 3283902

Browse files
committed
C++: Fix join that might blow up in the future.
1 parent 6380cc8 commit 3283902

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cpp/ql/src/Likely Bugs/Conversion/CastArrayPointerArithmetic.ql

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ class CastToPointerArithFlow extends DataFlow::Configuration {
2525

2626
override predicate isSource(DataFlow::Node node) {
2727
not node.asExpr() instanceof Conversion and
28-
introducesNewField(node.asExpr().getType().(DerivedType).getBaseType(),
29-
node.asExpr().getConversion*().getType().(DerivedType).getBaseType())
28+
exists(Type baseType1, Type baseType2 |
29+
hasBaseType(node.asExpr(), baseType1) and
30+
hasBaseType(node.asExpr().getConversion*(), baseType2) and
31+
introducesNewField(baseType1, baseType2)
32+
)
3033
}
3134

3235
override predicate isSink(DataFlow::Node node) {
@@ -35,6 +38,17 @@ class CastToPointerArithFlow extends DataFlow::Configuration {
3538
}
3639
}
3740

41+
/**
42+
* Gets the base type of `e` if the type of `e` is a `DerivedType`.
43+
*
44+
* This predicate ensures that joins go from `e` to `base` instead
45+
* of the other way around.
46+
*/
47+
pragma[inline]
48+
predicate hasBaseType(Expr e, Type base) {
49+
pragma[only_bind_into](base) = pragma[only_bind_out](e.getType().(DerivedType).getBaseType())
50+
}
51+
3852
/**
3953
* `derived` has a (possibly indirect) base class of `base`, and at least one new
4054
* field has been introduced in the inheritance chain after `base`.

0 commit comments

Comments
 (0)