Skip to content

Commit d68b060

Browse files
committed
C++: Use 'arrayTypeCand' in 'isSourceImpl' instead of checking for array size explicitly.
1 parent 3b4f2b2 commit d68b060

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-193/ConstantSizeArrayOffByOne.ql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ predicate isInvalidPointerDerefSink2(DataFlow::Node sink, Instruction i, string
7878
)
7979
}
8080

81-
predicate arrayTypeCand(ArrayType arrayType) { any(Variable v).getUnspecifiedType() = arrayType }
81+
predicate arrayTypeCand(ArrayType arrayType) {
82+
any(Variable v).getUnspecifiedType() = arrayType and
83+
exists(arrayType.getArraySize())
84+
}
8285

8386
pragma[nomagic]
8487
predicate arrayTypeHasSizes(ArrayType arr, int baseTypeSize, int arraySize) {
@@ -143,7 +146,7 @@ predicate isSourceImpl(DataFlow::Node source, Variable v) {
143146
or
144147
source.asInstruction().(VariableAddressInstruction).getAstVariable() = v
145148
) and
146-
exists(v.getUnspecifiedType().(ArrayType).getArraySize())
149+
arrayTypeCand(v.getUnspecifiedType())
147150
}
148151

149152
module ArrayAddressToDerefConfig implements DataFlow::StateConfigSig {

0 commit comments

Comments
 (0)