Attempt to Access Child of a Non-structure Pointer

Incomplete Variant
Structure: Simple
Description

Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption.

Common Consequences 2
Scope: Integrity

Impact: Modify Memory

Adjacent variables in memory may be corrupted by assignments performed on fields after the cast.

Scope: Availability

Impact: DoS: Crash, Exit, or Restart

Execution may end due to a memory access error.

Potential Mitigations 2
Phase: Requirements
The choice could be made to use a language that is not susceptible to these issues.
Phase: Implementation
Review of type casting operations can identify locations where incompatible types are cast.
Demonstrative Examples 1
The following example demonstrates the weakness.

Code Example:

Bad
C
c
Observed Examples 1
CVE-2021-3510JSON decoder accesses a C union using an invalid offset to an object
Modes of Introduction
Implementation
Taxonomy Mapping
  • Software Fault Patterns