1582
ChildOf 704 Incorrect Type Conversion or Cast 1538
Common Consequences
Scope Impact Likelihood
Integrity Modify Memory
Adjacent variables in memory may be corrupted by
assignments performed on fields after the cast.
Availability DoS: Crash, Exit, or Restart
Execution may end due to a memory access error.
Potential Mitigations
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
Example 1:
The following example demonstrates the weakness.
Example Language: C (Bad)
struct foo
{
int i;
}
...
int main(int argc, char **argv)
{
*foo = (struct foo *)main;
foo->i = 2;
return foo->i;
}
Observed Examples
Reference Description
CVE-2021-3510 JSON decoder accesses a C union using an invalid offset to an object
https://www.cve.org/CVERecord?id=CVE-2021-3510
CWE Version 4.14
CWE-589: Call to Non-ubiquitous API
CWE-589: Call to Non-ubiquitous API