detecting-integer-overflow
Detects integer overflow and underflow vulnerabilities in arithmetic operations used for buffer sizing or allocation. Use when analyzing calculations, size computations, or investigating integer wraparound issues.
When & Why to Use This Skill
This Claude skill specializes in identifying integer overflow and underflow vulnerabilities within arithmetic operations. By analyzing calculations used for buffer sizing, memory allocation, and loop bounds, it helps developers and security auditors prevent critical security exploits, such as buffer overflows and logic bypasses, through automated static analysis and impact assessment.
Use Cases
- Security Auditing: Automatically scanning legacy or complex C/C++ codebases to detect unsafe arithmetic patterns that could lead to integer wraparound.
- Secure Memory Management: Validating that size computations for dynamic memory allocation (e.g., malloc, realloc) include proper overflow protection and type checks.
- Logic Error Prevention: Investigating loop counters and array indexing logic to ensure that arithmetic operations do not inadvertently bypass security boundaries or cause infinite loops.
- Root Cause Analysis: Assisting developers in investigating known crashes or memory corruption issues by tracing user-controlled values through arithmetic operations.
| name | detecting-integer-overflow |
|---|---|
| description | Detects integer overflow and underflow vulnerabilities in arithmetic operations used for buffer sizing or allocation. Use when analyzing calculations, size computations, or investigating integer wraparound issues. |
Integer Overflow Detection
Detection Workflow
- Identify arithmetic operations: Find addition, multiplication, subtraction, bit shifts on user-controlled values
- Check for overflow protection: Look for overflow checks before arithmetic, safe arithmetic functions, type conversions
- Trace to critical uses: Follow results to memory allocation sizes, buffer copy lengths, loop bounds, array indices
- Assess impact: Can overflow cause buffer overflow? Bypass security checks? Cause logic errors?
Key Patterns
- Addition/multiplication without overflow checks
- Subtraction that could underflow
- Integer overflow affecting malloc size
- Loop counter overflow
Output Format
Report with: id, type (addition/multiplication/underflow), severity, confidence, location, operation, operands, result used for, overflow check status, exploitability, impact, mitigation.
Severity Guidelines
- HIGH: Overflow affects memory allocation size
- MEDIUM: Overflow affects loop bounds or array indices
- LOW: Overflow with limited security impact
See Also
patterns.md- Detailed detection patterns and exploitation scenariosexamples.md- Example analysis cases and code samplesreferences.md- CWE references and mitigation strategies