Skip to content

Commit 9c219b9

Browse files
authored
Merge pull request #225 from sauyon/sizeofcheck
Allow void* pointer arithmetic with sizeof
2 parents 8f19efe + 614a8ef commit 9c219b9

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

cpp/ql/src/Security/CWE/CWE-468/SuspiciousAddWithSizeof.ql

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@
1313
import cpp
1414
import IncorrectPointerScalingCommon
1515

16-
private predicate isCharPtrExpr(Expr e) {
16+
private predicate isCharSzPtrExpr(Expr e) {
1717
exists (PointerType pt
1818
| pt = e.getFullyConverted().getUnderlyingType()
19-
| pt.getBaseType().getUnspecifiedType() instanceof CharType)
19+
| pt.getBaseType().getUnspecifiedType() instanceof CharType
20+
or pt.getBaseType().getUnspecifiedType() instanceof VoidType)
2021
}
2122

2223
from Expr sizeofExpr, Expr e
2324
where
2425
// If we see an addWithSizeof then we expect the type of
25-
// the pointer expression to be char*. Otherwise it is probably
26-
// a mistake.
27-
addWithSizeof(e, sizeofExpr, _) and not isCharPtrExpr(e)
26+
// the pointer expression to be char* or void*. Otherwise it
27+
// is probably a mistake.
28+
addWithSizeof(e, sizeofExpr, _) and not isCharSzPtrExpr(e)
2829
select
2930
sizeofExpr,
3031
"Suspicious sizeof offset in a pointer arithmetic expression. " +

0 commit comments

Comments
 (0)