Stack Overflow
Overview
Stack overflows occur when the call stack exceeds available memory:
- Unbounded recursion: Recursive functions without base case or depth limit
- Large stack allocations: Variable-length arrays (VLAs) with user-controlled size
- Deep call chains: Complex XML/JSON parsing with deeply nested structures
In C/C++, stack overflows corrupt adjacent memory and can lead to code execution.
Remediation
- Add recursion depth limits
- Use iterative algorithms instead of recursive ones for user-controlled depth
- Validate nesting depth of parsed structures
- Use
ulimitor OS-level stack size limits