From 0e6936d418f0b9ad6e999521747479170ba45a79 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Mon, 3 Feb 2025 12:42:11 +0000 Subject: [PATCH] C++: Strip the type when computing the base type of a chain of qualifiers. --- cpp/ql/lib/semmle/code/cpp/commons/Buffer.qll | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cpp/ql/lib/semmle/code/cpp/commons/Buffer.qll b/cpp/ql/lib/semmle/code/cpp/commons/Buffer.qll index df2d04a97d7b..70d6795f76b0 100644 --- a/cpp/ql/lib/semmle/code/cpp/commons/Buffer.qll +++ b/cpp/ql/lib/semmle/code/cpp/commons/Buffer.qll @@ -49,7 +49,11 @@ private Class getRootType(FieldAccess fa) { exists(VariableAccess root | root = fa.getQualifier+() and not exists(root.getQualifier()) and - result = root.getUnspecifiedType() + // We strip the type because the root may be a pointer. For example `p` in: + // struct S { char buffer[10]; }; + // S* p = ...; + // strcpy(p->buffer, "abc"); + result = root.getUnspecifiedType().stripType() ) }