Description
Wrap around errors occur whenever a value is incremented past the maximum value for its type and therefore "wraps around" to a very small, negative, or undefined value.
Potential Impact
Availability
DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Instability
Integrity
Modify Memory
Confidentiality, Availability, Access Control
Execute Unauthorized Code or Commands, Bypass Protection Mechanism
Demonstrative Examples
img_t table_ptr; /*struct containing img data, 10kB each*/int num_imgs;...num_imgs = get_num_imgs();table_ptr = (img_t*)malloc(sizeof(img_t)*num_imgs);...Mitigations & Prevention
Requirements specification: The choice could be made to use a language that is not susceptible to these issues.
Provide clear upper and lower bounds on the scale of any protocols designed.
Perform validation on all incremented variables to ensure that they remain within reasonable bounds.
Detection Methods
- Automated Static Analysis High — Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then sea
Related Weaknesses
Taxonomy Mappings
- CLASP: — Wrap-around error
- CERT C Secure Coding: MEM07-C — Ensure that the arguments to calloc(), when multiplied, can be represented as a size_t
- Software Fault Patterns: SFP1 — Glitch in computation
Frequently Asked Questions
What is CWE-128?
CWE-128 (Wrap-around Error) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. Wrap around errors occur whenever a value is incremented past the maximum value for its type and therefore "wraps around" to a very small, negative, or undefined value.
How can CWE-128 be exploited?
Attackers can exploit CWE-128 (Wrap-around Error) to dos: crash, exit, or restart, dos: resource consumption (cpu), dos: resource consumption (memory), dos: instability. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-128?
Key mitigations include: Requirements specification: The choice could be made to use a language that is not susceptible to these issues.
What is the severity of CWE-128?
CWE-128 is classified as a Base-level weakness (Medium abstraction). Its actual severity depends on the specific context and how the weakness manifests in your application.