2024 CWE Top 25 Most Dangerous Software Weaknesses: Integer Overflow or Wraparound (CWE-190)
The Common Weakness Enumeration (CWE) is a repository of software vulnerabilities designed to guide developers and architects in identifying and mitigating common security pitfalls. Among the CWE Top 25 Most Dangerous Software Weaknesses of 2024, Integer Overflow or Wraparound (CWE-190) holds significant importance. This weakness is a silent yet powerful adversary that can lead to devastating consequences if not addressed during the software development lifecycle.
In this blog post, we’ll delve into the intricacies of CWE-190, exploring its mechanics, impacts, detection methods, and best practices for mitigation. By the end, you will be equipped with a comprehensive understanding to bolster your software systems against this critical vulnerability.
Understanding Integer Overflow or Wraparound
What is Integer Overflow or Wraparound?
Integer Overflow occurs when an arithmetic operation attempts to create a numeric value that exceeds the maximum limit of the data type used to store it. Similarly, Integer Wraparound happens when the numeric value “wraps around”, cycling back to the minimum limit.
For example, in a 32-bit signed integer:
- Maximum value: 2,147,483,647
- Minimum value: -2,147,483,648
An addition of 1 to the maximum value results in wraparound to the minimum value, potentially causing incorrect logic and vulnerabilities in software.
Real-World Example
Consider an e-commerce platform calculating total order costs. If an attacker manipulates the quantity of an expensive item to a value that causes an integer overflow, the total cost might reset to a significantly low (or even negative) value, enabling the attacker to acquire items at a negligible cost.
Here are notable real-world cyber incidents involving CWE-190 (Integer Overflow or Wraparound):
1. Heartbleed Vulnerability in OpenSSL (2014)
- Overview: The Heartbleed bug was an infamous security flaw in OpenSSL\u2019s heartbeat extension.
- CWE Connection: While primarily a buffer over-read vulnerability, Heartbleed indirectly stemmed from improper input validation, where unchecked user input could lead to unexpected arithmetic results.
- Impact: Allowed attackers to read sensitive data from the server\u2019s memory, including SSL keys, usernames, and passwords.
- Lesson: Enforcing boundary checks during arithmetic operations is crucial to prevent overflows that enable such vulnerabilities.
2. Ethereum Smart Contract Hack (2016)
- Overview: An attacker exploited a vulnerability in the Decentralised Autonomous Organisation (DAO) smart contract on the Ethereum blockchain.
- CWE Connection: Integer overflow was used to manipulate transaction calculations, draining over $60 million worth of Ethereum.
- Impact: Triggered a hard fork in the Ethereum blockchain to reverse the theft.
- Lesson: Use safe arithmetic operations and explicitly validate input values in smart contracts to prevent exploitation.
3. Boeing 787 Dreamliner Software Bug (2015)
- Overview: A software bug in the 787 Dreamliner\u2019s onboard systems caused an integer overflow after 248 days of continuous operation.
- CWE Connection: Integer wraparound led to a reset of critical flight control systems, potentially endangering lives.
- Impact: Required manual software resets to prevent system failures.
- Lesson: Include robust handling for edge cases in safety-critical systems to ensure operational stability.
4. PHP Integer Overflow in Image Processing (2019)
- Overview: A vulnerability in PHP\u2019s exif_read_data() function led to an integer overflow during image metadata parsing.
- CWE Connection: The vulnerability allowed attackers to execute arbitrary code by supplying a crafted image.
- Impact: Enabled remote code execution on affected systems.
- Lesson: Adopt libraries that perform safe arithmetic operations, especially for handling untrusted input.
5. Nintendo Switch Homebrew Vulnerability (2018)
- Overview: The Tegra X1 processor in the Nintendo Switch had an integer overflow vulnerability in its USB recovery mode.
- CWE Connection: The overflow allowed attackers to bypass security and run unauthorised code on the device.
- Impact: Enabled the use of homebrew software but also facilitated piracy and potential malware infections.
- Lesson: Validate inputs in low-level hardware operations to ensure security.
6. Cloudflare Web Application Exploit (2020)
- Overview: Researchers discovered a vulnerability in Cloudflare\u2019s WAF (Web Application Firewall) due to integer overflow in boundary checks for HTTP headers.
- CWE Connection: The flaw allowed attackers to bypass security rules, exposing sensitive customer data.
- Impact: Highlighted the risks of improper arithmetic validations in security-critical middleware.
- Lesson: Integrate static analysis tools to detect integer overflow vulnerabilities in complex systems.
7. Google Chrome Skia Integer Overflow Vulnerability (2023)
- Overview: An integer overflow was identified in the Skia graphics library used by Google Chrome. This flaw allowed a remote attacker, who had already compromised the renderer process, to potentially perform a sandbox escape via a crafted HTML page.
- Impact: Active exploitation of this vulnerability was acknowledged, highlighting its severity. The issue was addressed in a subsequent update to the Chrome browser.
- Lesson: This incident underscores the importance of promptly updating software to mitigate known vulnerabilities and the need for continuous monitoring of third-party libraries integrated into applications.
8. Apple Kernel Integer Overflow Vulnerability (2023)
- Overview: An integer overflow vulnerability in the kernel affected multiple Apple products, including iOS, iPadOS, macOS, and watchOS. This flaw allowed an application to execute arbitrary code with kernel privileges.
- Impact: The issue may have been actively exploited on older versions of iOS. The vulnerability was mitigated with improved input validation in software updates.
- Lesson: This highlights the critical need for regular software updates and the implementation of robust input validation mechanisms to prevent privilege escalation attacks.
9. Google Chrome USB Integer Overflow Vulnerability (2023)
- Overview: An integer overflow was discovered in the USB component of Google Chrome. It potentially allowed a remote attacker to exploit heap corruption via a crafted HTML page.
- Impact: Classified with high severity, this flaw prompted users to update to the latest version to mitigate potential risks.
- Lesson: This case emphasizes the necessity for developers to conduct thorough testing of all browser components, including those handling external devices, to identify and rectify integer overflow vulnerabilities.
10. iperf3 Integer Overflow and Heap Corruption (2023)
- Overview: A vulnerability in iperf3 allowed a malicious peer to trigger an integer overflow and subsequent heap corruption by manipulating the length field.
- Impact: Exploitation of this flaw could lead to arbitrary code execution or application crashes, posing significant risks to system integrity.
- Lesson: This incident highlights the importance of validating input lengths and implementing proper bounds checking to prevent integer overflow vulnerabilities.
Key Takeaways:
- Integer overflows are prevalent across industries, from blockchain to aviation.
- The consequences range from data breaches and financial losses to potential loss of life.
- Mitigations like rigorous input validation, use of safe libraries, and boundary testing are vital to address these vulnerabilities proactively.
Would you like to delve deeper into any specific incident?
Why is it Dangerous?
The risks associated with Integer Overflow include:
- Security Breaches: Exploitable weaknesses that attackers can use to gain unauthorised access or manipulate system behaviours.
- Data Corruption: Alteration or loss of critical data.
- Application Crashes: System instability, leading to downtime and loss of user trust.
Root Causes of CWE-190
Data Type Limitations
Programming languages have predefined limits for numeric data types. When operations exceed these limits, undefined behaviours occur, leading to potential vulnerabilities.
Lack of Input Validation
Failing to validate or sanitise input data creates opportunities for attackers to introduce values that trigger overflow.
Misuse of Arithmetic Operations
Improper handling of mathematical computations, especially in loops and iterative processes, often results in integer overflow.
Inadequate Testing
Relying solely on functional testing without accounting for edge cases related to data boundaries is a common oversight.
Common Scenarios of Exploitation
- Buffer Overflows: Integer overflows can lead to miscalculated buffer sizes, resulting in memory corruption.
- Privilege Escalation: Exploiting arithmetic vulnerabilities to bypass access control mechanisms.
- Denial of Service (DoS): Overflows causing application crashes or unresponsiveness.
Example: Buffer Overflow Exploitation
#include <stdio.h>
#include <string.h>
void copyString(char *destination, char *source, int length) {
if (length > 0) {
char buffer[length];
strcpy(buffer, source); // Potential buffer overflow
strcpy(destination, buffer);
}
}
int main() {
char src[] = “AttackPayload”;
char dest[10];
copyString(dest, src, 4294967295); // Integer overflow leads to incorrect
buffer size
return 0;
}
In this code, the length parameter overflows, resulting in an incorrectly allocated buffer size and a subsequent buffer overflow.
Detection and Mitigation Strategies
Detection Methods
- Static Analysis Tools Tools like SonarQube, Coverity, and Fortify help identify potential overflow vulnerabilities by analysing source code.
- Dynamic Analysis Techniques like fuzz testing and runtime monitoring can uncover integer overflows during execution.
- Boundary Testing Manually testing edge cases involving maximum and minimum data type limits.
Mitigation Techniques
1. Input Validation
Validate all inputs to ensure they fall within acceptable ranges.
if (input < 0 || input > MAX_ALLOWED_VALUE) {
printf(“Invalid input\\n”);
return;
}
2. Use of Safe Libraries
Leverage libraries and functions that provide built-in checks for arithmetic operations, such as SafeInt in C++.
3. Adherence to Secure Coding Standards
Follow guidelines like CERT C Coding Standards or OWASP Secure Coding Practices.
4. Avoid Implicit Casting
Explicitly define data types and casting to prevent unintended behaviours.
5. Enable Compiler Warnings
Use compiler flags such as -ftrapv in GCC to detect and trap integer overflows.
6. Regular Code Reviews
Incorporate peer reviews and security audits to identify overlooked vulnerabilities.
Business Impact and Risk Mitigation
Financial Losses
Integer overflows can lead to fraud, data breaches, and system downtime, all of which have direct financial implications.
Reputational Damage
Security incidents stemming from avoidable vulnerabilities erode customer trust and damage brand reputation.
Regulatory Penalties
Non-compliance with data protection and security regulations, such as GDPR or CCPA, can result in hefty fines.
ROI of Proactive Measures
Investing in secure coding practices, automated testing tools, and training developers on vulnerabilities like CWE-190 can significantly reduce costs associated with breaches and remediations.
Tools and Frameworks
Tools for Detection and Prevention
- Static Analysis Tools: SonarQube, Coverity
- Dynamic Testing: AFL (American Fuzzy Lop), Valgrind
- Specialised Libraries: SafeInt (C++), BigInteger (Java)
Frameworks for Secure Development
- OWASP Software Assurance Maturity Model (SAMM)
- Microsoft Security Development Lifecycle (SDL)
Real-World Case Studies
Case Study 1: Banking Application Vulnerability
A major bank faced a breach where an integer overflow allowed attackers to manipulate transaction values. Implementing input validation and boundary checks mitigated the issue.
Case Study 2: Video Game Glitch
An online multiplayer game experienced an exploit where players could overflow currency counters to gain unlimited in-game funds. Addressing the overflow with safe arithmetic operations resolved the vulnerability.
SAST and DAST to discover the Integer overflow vulnerabilities
Static Application Security Testing (SAST) and Dynamic Application Security Testing (DAST) are essential tools for discovering integer overflow vulnerabilities, each offering unique approaches and benefits.
Static Application Security Testing (SAST)
What is SAST?
SAST involves analysing the source code, bytecode, or binaries of an application without executing it. It identifies vulnerabilities, including integer overflows, early in the development lifecycle.
How SAST Detects Integer Overflow Vulnerabilities
- Code Analysis:
- Scans source code for patterns indicating potential overflow, such as unchecked arithmetic operations.
- Flags operations involving large data types (e.g., 32-bit or 64-bit integers) and implicit casting.
- Highlights instances of dangerous functions or constructs known to cause overflow.
- Boundary Condition Checks:
- Identifies logic gaps where boundary conditions are not explicitly defined.
- Detects the absence of checks for maximum and minimum limits of data types.
- Custom Rules:
- Allows developers to define specific rules tailored to identify overflow risks in application-specific contexts.
Advantages of SAST
- Early Detection: Identifies vulnerabilities during development, reducing remediation costs.
- Comprehensive Coverage: Analyses the entire codebase for potential issues.
- Integration: Works seamlessly with CI/CD pipelines to enforce secure coding practices.
Limitations of SAST
- False Positives: Can flag non-issues, requiring manual review.
- Limited Runtime Context: Cannot identify vulnerabilities caused by runtime data or environment-specific behaviours.
Popular SAST Tools for Integer Overflow Detection
- Checkmarx
- Coverity
- Fortify Static Code Analyzer
- SonarQube
Dynamic Application Security Testing (DAST)
What is DAST?
DAST tests an application in its runtime environment, simulating attacks to identify vulnerabilities. It does not require access to the source code and works on a black-box approach.
How DAST Detects Integer Overflow Vulnerabilities
- Fuzz Testing:
- Sends large or malformed input values to application endpoints to identify overflow conditions.
- Monitors application behaviour for crashes, unexpected responses, or performance issues.
- Boundary Value Testing:
- Explores edge cases, such as maximum and minimum data type limits, to detect wraparound or overflow behaviour.
- Automated Payloads:
- Injects crafted inputs that exploit arithmetic operations to trigger potential overflows.
Advantages of DAST
- Runtime Insights: Observes actual application behaviour under real-world conditions.
- No Code Access Needed: Suitable for third-party or legacy applications where source code is unavailable.
- Dynamic Context: Identifies vulnerabilities caused by runtime data and environmental factors.
Limitations of DAST
- Late Detection: Discovers vulnerabilities later in the development lifecycle, increasing remediation costs.
- Limited Code Coverage: May not test all code paths or logic conditions.
- Slower Feedback Loop: Takes more time compared to SAST due to runtime execution.
Popular DAST Tools for Integer Overflow Detection
- Burp Suite
- OWASP ZAP (Zed Attack Proxy)
- AppSpider
- Acunetix
SAST vs DAST: Complementary Approaches
Feature | SAST | DAST |
Stage | Development | Runtime |
Access | Requires source code | No code access needed |
Detection Scope | Code-level issues | Runtime behaviour issues |
Detection Speed | Faster | Slower |
Examples Detected | Missing boundary checks | Overflow under high input values |
SAST and DAST are complementary rather than competing approaches. Using both in tandem ensures comprehensive security testing, catching vulnerabilities at both code and runtime levels.
Best Practices for Using SAST and DAST
- Integrate Early and Continuously:
- Use SAST during development to prevent vulnerabilities.
- Use DAST during testing and staging for runtime validation.
- Customise Rules and Payloads:
- Tailor tools to your application\u2019s specific logic and business cases.
- Combine with Manual Code Reviews:
- Supplement automated testing with manual reviews for context-specific insights.
- Prioritise Remediation:
- Address flagged vulnerabilities based on their risk impact and likelihood of exploitation.
By leveraging SAST and DAST effectively, software teams can identify and mitigate integer overflow vulnerabilities, ensuring robust and secure applications.
Runtime Application Self-Protection (RAST)
Runtime Application Self-Protection (RAST) can indeed help in addressing Integer Overflow vulnerabilities (CWE-190), complementing traditional tools like SAST and DAST by offering real-time protection and monitoring.
What is RAST?
RAST is a security mechanism embedded within an application. It actively monitors and protects applications during runtime by analysing their behaviour and detecting potential vulnerabilities or attacks, including integer overflows.
How RAST Helps with Integer Overflow Vulnerabilities
- Real-Time Detection:
- Monitors arithmetic operations and alerts or blocks execution if an integer overflow or wraparound is detected.
- Prevents exploits from succeeding by intervening during runtime.
- Input Validation at Runtime:
- Validates inputs dynamically, even if developers fail to include proper validation during coding.
- Ensures that boundary conditions and data types are not violated during execution.
- Instrumentation-Based Insights:
- Embeds security checks within the application to track critical functions prone to overflows, such as loops and arithmetic calculations.
- Generates logs for suspicious behaviours, aiding in forensic analysis and debugging.
- Integration with Development and Testing:
- Provides actionable insights during testing phases to refine code and enhance security measures.
- Enables immediate feedback when overflow vulnerabilities are triggered.
Advantages of Using RAST
- Context-Aware Protection:
- Unlike SAST and DAST, RAST operates with complete context, including runtime data, application state, and environment specifics.
- Immediate Mitigation:
- Blocks exploits in real-time, reducing the risk of breaches and downtime.
- Complementary Approach:
- Works alongside SAST and DAST to fill gaps by catching vulnerabilities that emerge in complex, dynamic conditions.
Challenges of Using RAST
- Performance Overhead:
- Runtime monitoring can introduce latency or impact application performance if not optimised.
- Implementation Complexity:
- Requires integration into the application, which can be challenging for legacy or third-party systems.
- Limited Prevention Scope:
- While it mitigates vulnerabilities at runtime, it does not fix the root cause in the codebase.
Best Practices for Leveraging RAST for Integer Overflow
- Deploy with Critical Applications:
- Use RAST in applications handling sensitive data or critical operations prone to integer overflows.
- Customise Rules:
- Define specific runtime checks for arithmetic operations and boundary conditions.
- Combine with Other Tools:
- Integrate RAST with SAST, DAST, and manual reviews to ensure comprehensive coverage.
- Monitor and Refine:
- Continuously monitor logs and adjust detection rules based on observed application behaviours and emerging threats.
RAST in the Secure Software Development Lifecycle
RAST complements SAST and DAST by offering runtime protection, closing the loop on vulnerabilities that static and dynamic testing might miss. While SAST identifies issues early, and DAST tests runtime behaviour, RAST ensures that any unaddressed vulnerabilities are mitigated in real-time.
RAST adds significant value to an organisation\u2019s security toolkit by providing real-time monitoring and defence against Integer Overflow vulnerabilities. While it is not a standalone solution, its integration with other security measures creates a layered defence strategy, reducing the risk of exploitation and ensuring robust application security.
Final Thoughts
Integer Overflow or Wraparound (CWE-190) represents a critical yet often underestimated vulnerability. By understanding its root causes, risks, and mitigations, software developers and architects can design resilient systems that safeguard user trust and organisational assets. Remember, addressing CWE-190 is not just about writing secure code but also about fostering a security-first mindset across all stages of software development.

As a final takeaway, prioritise secure coding practices, leverage automated tools, and stay informed about evolving threats. After all, in the battle against vulnerabilities, knowledge and preparation are your strongest allies.