CWE-121: Stack-based Buffer Overflow

VariantDraftExploit Likelihood: High

A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function).

View on MITRE
Back to CWE Lookup

Technical Details

Structure
Simple
Vulnerability Mapping
ALLOWED

Applicable To

Languages
CC++Memory-Unsafe
Platforms

Source-backed guidance

Additional facts reviewed against primary or authoritative security sources.

Combine review and analysis around the CWE-121 trust boundary

MITRE identifies fuzzing, automated static analysis, automated dynamic analysis as applicable detection approaches. Use them to identify fixed-size local arrays and prove every write, copy, format operation, and terminator remains within the stack object. Require a reproducible source-to-sink or policy-to-enforcement trace, record coverage gaps, and confirm suspected findings dynamically where safe; no single scanner can establish complete coverage for this weakness.

CWE-121: detection methods and operational guidanceMITRE CWE

Remove stack-buffer overflow paths instead of relying on crash defenses

Use a memory-safe language for new code and migrate externally reachable memory-unsafe components where feasible. For remaining stack buffers, prove bounds before copies and writes, check size calculations, replace unbounded interfaces, and test boundary-length inputs with static and runtime memory-safety tooling. Compiler hardening can limit exploitation but does not correct the underlying out-of-bounds access.

Secure by Design Alert: Eliminating Buffer Overflow VulnerabilitiesCISA

Apply lessons from CVE-2025-22457 in Ivanti Connect Secure, Policy Secure, and ZTA Gateways

NVD maps CVE-2025-22457 to CWE-121; a stack-based buffer overflow exposed to unauthenticated remote input could lead to remote code execution. Use the case to prioritize pre-authentication appliance code, fuzz protocol boundaries, and treat a stack crash as a potential control-flow compromise requiring immediate remediation.

CVE-2025-22457 DetailNIST National Vulnerability Database

Prioritize CWE-121 using its 2025 CWE Top 25 evidence

CWE-121 ranked #14 in the 2025 CWE Top 25 with a score of 5.75. The ranking table recorded 4 mapped vulnerabilities in CISA KEV for this measurement window. Use the rank to prioritize systemic prevention, detection coverage, and recurring-root-cause metrics across the portfolio, while retaining asset exposure and business impact for individual finding severity decisions.

2025 CWE Top 25 Most Dangerous Software WeaknessesMITRE CWE

Fuzz stack-buffer boundaries under AddressSanitizer

Build native targets with AddressSanitizer and fuzz each parser or protocol field copied into a local array. Include exact-fit, one-byte-too-large, missing-terminator, nested, and maximum-size values plus error paths. Preserve stack traces and crashing inputs, then verify the fix removes the fixed buffer or proves capacity before each write; stack canaries alone do not establish memory safety.

AddressSanitizerLLVM Project

Frequently Asked Questions

What is CWE-121: Stack-based Buffer Overflow?+

CWE-121: Stack-based Buffer Overflow is a Common Weakness Enumeration (CWE) entry maintained by MITRE. A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function).

What are the security consequences of Stack-based Buffer Overflow?+

If exploited, CWE-121 (Stack-based Buffer Overflow) it can compromise Availability, Integrity, Confidentiality, Access Control and Other, leading to outcomes such as Modify Memory, DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), Execute Unauthorized Code or Commands and Bypass Protection Mechanism.

How do you prevent or mitigate Stack-based Buffer Overflow?+

Recommended mitigations for CWE-121 include: Use an abstraction library to abstract away risky APIs. Not a complete solution. Implement and perform bounds checking on input. Do not use dangerous functions such as gets. Use safer, equivalent functions which check for boundary errors.

Which programming languages are affected by Stack-based Buffer Overflow?+

CWE-121 commonly affects C, C++ and Memory-Unsafe. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What are real-world examples of Stack-based Buffer Overflow?+

MITRE documents real CVEs mapped to CWE-121, including CVE-2021-35395. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-121 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.

Learn More

Advertisement