CWE-469
Use of Pointer Subtraction to Determine Size
AI Translation Available
The product subtracts one pointer from another in order to determine size, but this calculation can be incorrect if the pointers do not exist in the same memory chunk.
Status
draft
Abstraction
base
Likelihood
medium
Affected Platforms
C
C++
Technical Details
AI Translation
Common Consequences
access control
integrity
confidentiality
availability
Impacts
modify memory
read memory
execute unauthorized code or commands
gain privileges or assume identity
Detection Methods
fuzzing
automated static analysis
Potential Mitigations
Phases:
implementation
Descriptions:
•
Save an index variable. This is the recommended solution. Rather than subtract pointers from one another, use an index variable of the same size as the pointers in question. Use this variable to "walk" from one pointer to the other and calculate the difference. Always validate this number.