CWE-467: Use of sizeof() on a Pointer Type

VariantDraftExploit Likelihood: High

The code calls sizeof() on a pointer type, which can be an incorrect calculation if the programmer intended to determine the size of the data that is being pointed to.

View on MITRE
Back to CWE Lookup

Extended Description

The use of sizeof() on a pointer can sometimes generate useful information. An obvious case is to find out the wordsize on a platform. More often than not, the appearance of sizeof(pointer) indicates a bug.

Technical Details

Structure
Simple

Applicable To

Languages
CC++
Platforms

Frequently Asked Questions

What is CWE-467: Use of sizeof() on a Pointer Type?+

CWE-467: Use of sizeof() on a Pointer Type is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The code calls sizeof() on a pointer type, which can be an incorrect calculation if the programmer intended to determine the size of the data that is being pointed to. The use of sizeof() on a pointer can sometimes generate useful information. An obvious case is to find out the wordsize on a platform. More often than not, the appearance of sizeof(pointer) indicates a bug.

What are the security consequences of Use of sizeof() on a Pointer Type?+

If exploited, CWE-467 (Use of sizeof() on a Pointer Type) it can compromise Integrity and Confidentiality, leading to outcomes such as Modify Memory and Read Memory.

How do you prevent or mitigate Use of sizeof() on a Pointer Type?+

Recommended mitigations for CWE-467 include: Use expressions such as "sizeof(*pointer)" instead of "sizeof(pointer)", unless you intend to run sizeof() on a pointer type to gain some platform independence or if you are allocating a variable on the stack.

Which programming languages are affected by Use of sizeof() on a Pointer Type?+

CWE-467 commonly affects C and C++. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-467 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.

Learn More

CWE-467: Use of sizeof() on a Pointer Type | CWE Lookup | InventiveHQ