From 437c67926640bfeffb62363b627d0949159f7e26 Mon Sep 17 00:00:00 2001 From: Geoffrey White <40627776+geoffw0@users.noreply.github.com> Date: Mon, 22 Jul 2024 18:09:08 +0100 Subject: [PATCH] C++: Switch to using the Buffer.qll implementation directly. --- cpp/ql/src/Critical/SizeCheck2.ql | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cpp/ql/src/Critical/SizeCheck2.ql b/cpp/ql/src/Critical/SizeCheck2.ql index f2240ba623a..3ce86564199 100644 --- a/cpp/ql/src/Critical/SizeCheck2.ql +++ b/cpp/ql/src/Critical/SizeCheck2.ql @@ -15,6 +15,7 @@ import cpp import semmle.code.cpp.models.Models +import semmle.code.cpp.commons.Buffer predicate baseType(AllocationExpr alloc, Type base) { exists(PointerType pointer | @@ -35,15 +36,6 @@ predicate decideOnSize(Type t, int size) { size = min(t.getSize()) } -predicate mayHaveVarSize(Type t) { - // a member (normally at the end of the type) that looks like it may be intended have variable size. - exists(MemberVariable mv, ArrayType at | - mv.getDeclaringType() = t and - mv.getUnspecifiedType() = at and - not at.getArraySize() > 1 - ) -} - from AllocationExpr alloc, Type base, int basesize, int allocated where baseType(alloc, base) and @@ -56,7 +48,7 @@ where (allocated / size) * size = allocated ) and not basesize > allocated and // covered by SizeCheck.ql - not mayHaveVarSize(base.getUnspecifiedType()) // exclude variable size types + not memberMayBeVarSize(base.getUnspecifiedType(), _) // exclude variable size types select alloc, "Allocated memory (" + allocated.toString() + " bytes) is not a multiple of the size of '" + base.getName() + "' (" + basesize.toString() + " bytes)."