Umbra Wiki weakness weakness/CWE-467
Back to wiki

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

provenance: imported · CWE: CWE-467

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

MITRE CWE weakness

Kind Weakness
Abstraction Variant
Status Draft
Likelihood of exploit High

Description

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.

Common consequences

  • Integrity, Confidentiality: Modify Memory, Read Memory

Mitigations

Implementation — 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.

References

  • CWE page: https://cwe.mitre.org/data/definitions/467.html
  • CWE list: https://cwe.mitre.org/data/index.html