Stack Overflow Vulnerability

Detects code patterns that can cause stack overflows via unbounded recursion or excessive stack allocation.

zakirkun Updated

File contents

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 ulimit or OS-level stack size limits

zakirkun/ice-tea/tree/main/skills/memory/stack-overflow commit b1c675caca

Frequently asked questions

npx skillmds@latest add zakirkun/stack-overflow-vulnerability