mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Allow void* pointer arithmetic with sizeof
Technically this isn't allowed by the C spec, but it's been seen in the wild:
see 3763c7b338/files/src/csp_buffer.c\#x1d04047d2bb68c21:1
This commit is contained in:
@@ -13,18 +13,19 @@
|
||||
import cpp
|
||||
import IncorrectPointerScalingCommon
|
||||
|
||||
private predicate isCharPtrExpr(Expr e) {
|
||||
private predicate isCharSzPtrExpr(Expr e) {
|
||||
exists (PointerType pt
|
||||
| pt = e.getFullyConverted().getUnderlyingType()
|
||||
| pt.getBaseType().getUnspecifiedType() instanceof CharType)
|
||||
| pt.getBaseType().getUnspecifiedType() instanceof CharType
|
||||
or pt.getBaseType().getUnspecifiedType() instanceof VoidType)
|
||||
}
|
||||
|
||||
from Expr sizeofExpr, Expr e
|
||||
where
|
||||
// If we see an addWithSizeof then we expect the type of
|
||||
// the pointer expression to be char*. Otherwise it is probably
|
||||
// a mistake.
|
||||
addWithSizeof(e, sizeofExpr, _) and not isCharPtrExpr(e)
|
||||
// the pointer expression to be char* or void*. Otherwise it
|
||||
// is probably a mistake.
|
||||
addWithSizeof(e, sizeofExpr, _) and not isCharSzPtrExpr(e)
|
||||
select
|
||||
sizeofExpr,
|
||||
"Suspicious sizeof offset in a pointer arithmetic expression. " +
|
||||
|
||||
Reference in New Issue
Block a user