CWE-120 / WEAKNESS
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer.
- Category
- CWE weaknesses
- Version / scope
- CWE 4.20; release 2026-04-30; publisher status Incomplete
- Affected / relevant technologies
- Memory-Unsafe / C / C++ / Assembly
- Evidence
- Documentation: pinned-source excerpt checked. Execution: not tested. Editorial: curated reference.
Defensive analysis and explicitly authorized assessment only. This website performs no scans, exploitation, model calls or infrastructure changes. Indicators below are investigation opportunities, not proof of compromise or guaranteed detectors.
Mechanism and prerequisites
No separate exploit prerequisites are asserted here; the publisher's weakness/pattern context must be matched to the implementation.
Potential impact
Integrity Confidentiality Availability Modify Memory Execute Unauthorized Code or Commands Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of the product's implicit security policy. This can often be used to subvert any other security service. Availability Modify Memory DoS: Crash, Exit, or Restart DoS: Resource Consumption (CPU) Buffer overflows generally lead to crashes. Other attacks leading to lack of availability are possible, including putting the product into an infinite loop.
Versioned source scope
This record contains normalized, sometimes shortened source excerpts with editorial safety context. Markup and executable example blocks are omitted. Source-field verification does not establish device testing, a working detector or local applicability.
Publisher: MITRE. Release: CWE 4.20; release 2026-04-30; publisher status Incomplete. Source checked: 2026-11-18.
Source object: CWE-120. Object modified: 2026-01-21.
Attribution and source terms (© The MITRE Corporation; reproduced with permission)Detection and investigation
- Automated Static Analysis This weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives. Automated static analysis generally does not account for environmental considerations when reporting out-of-bounds memory operations. This can make it difficult for users to determine which warnings should be investigated first. For example, an analysis tool might report buffer overflows that originate from command line arguments in a program that is not expected to run with setuid or other special privileges. High Detection techniques for buffer-related errors are more mature than for most other weakness types.
- Automated Dynamic Analysis This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.
- Manual Analysis Manual analysis can be useful for finding this weakness, but it might not achieve desired code coverage within limited time constraints. This becomes difficult for weaknesses that must be considered for all inputs, since the attack surface can be too large.
- Automated Dynamic Analysis Use tools that are integrated during compilation to insert runtime error-checking mechanisms related to memory safety errors, such as AddressSanitizer (ASan) for C/C++ [REF-1518]. Moderate Crafted inputs are necessary to reach the code containing the error, such as generated by fuzzers. Also, these tools may reduce performance, and they only report the error condition - not the original mistake that led to the error.
Preserve source timestamps, asset identity and collection context. Correlate independent evidence before attributing malicious intent. In OT, review passive evidence with the process owner; do not induce failures, replay commands or write to controllers to test a hypothesis.
Mitigation and response
- Requirements Language Selection Use a language that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. For example, many languages that perform their own memory management, such as Java and Perl, are not subject to buffer overflows. Other languages, such as Ada and C#, typically provide overflow protection, but the protection can be disabled by the programmer. Be wary that a language's interface to native code may still be subject to overflows, even if the language itself is theoretically safe.
- Architecture and Design Libraries or Frameworks Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid. Examples include the Safe C String Library (SafeStr) by Messier and Viega [REF-57], and the Strsafe.h library from Microsoft [REF-56]. These libraries provide safer versions of overflow-prone string-handling functions. This is not a complete solution, since many buffer overflows are not related to strings.
- Operation Build and Compilation Environment Hardening Use automatic buffer overflow detection mechanisms that are offered by certain compilers or compiler extensions. Examples include: the Microsoft Visual Studio /GS flag, Fedora/Red Hat FORTIFY_SOURCE GCC flag, StackGuard, and ProPolice, which provide various mechanisms including canary-based detection and range/index checking. D3-SFCV (Stack Frame Canary Validation) from D3FEND [REF-1334] discusses canary-based detection in detail. Defense in Depth This is not necessarily a complete solution, since these mechanisms only detect certain types of overflows. In addition, the result is still a denial of service, since the typical response is to exit the application.
- Implementation Consider adhering to the following rules when allocating and managing an application's memory: Double check that your buffer is as large as you specify. When using functions that accept a number of bytes to copy, such as strncpy(), be aware that if the destination buffer size is equal to the source buffer size, it may not NULL-terminate the string. Check buffer boundaries if accessing the buffer in a loop and make sure there is no danger of writing past the allocated space. If necessary, truncate all input strings to a reasonable length before passing them to the copy and concatenation functions.
Apply changes through the asset owner's approved change and recovery process. Documentation review is separate from successful testing or verified production protection.
Related technical context
No protocol-specific mapping is asserted for this entry.
Related security reading
Continue directly to another reference. Editorial reading connections do not assert official CWE/CAPEC/ATT&CK/OWASP equivalence or mappings.
Publisher weakness and attack-pattern relationships
These relationships retain the publisher's source attributes and view context; they do not establish that an attack or weakness applies to a particular system.
- CAPEC-10 → Related_Weakness → CWE-120 Open related reference
- CAPEC-100 → Related_Weakness → CWE-120 Open related reference
- CAPEC-14 → Related_Weakness → CWE-120 Open related reference
- CAPEC-24 → Related_Weakness → CWE-120 Open related reference
- CAPEC-42 → Related_Weakness → CWE-120 Open related reference
- CAPEC-44 → Related_Weakness → CWE-120 Open related reference
- CAPEC-45 → Related_Weakness → CWE-120 Open related reference
- CAPEC-46 → Related_Weakness → CWE-120 Open related reference
- CAPEC-47 → Related_Weakness → CWE-120 Open related reference
- CAPEC-67 → Related_Weakness → CWE-120 Open related reference
- CAPEC-8 → Related_Weakness → CWE-120 Open related reference
- CAPEC-9 → Related_Weakness → CWE-120 Open related reference
- CAPEC-92 → Related_Weakness → CWE-120 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-10 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-100 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-14 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-24 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-42 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-44 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-45 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-46 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-47 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-67 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-8 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-9 Open related reference
- CWE-120 → Related_Attack_Pattern → CAPEC-92 Open related reference
- CWE-120 → ChildOf → CWE-119 Open related reference
- CWE-120 → CanPrecede → CWE-123 Open related reference
- CWE-120 → ChildOf → CWE-20 Open related reference
- CWE-120 → ChildOf → CWE-787 Open related reference
- CWE-120 → ChildOf → CWE-787 Open related reference
- CWE-120 → ChildOf → CWE-787 Open related reference
- CWE-170 → CanPrecede → CWE-120 Open related reference
- CWE-231 → CanPrecede → CWE-120 Open related reference
- CWE-416 → CanPrecede → CWE-120 Open related reference
- CWE-456 → CanPrecede → CWE-120 Open related reference
Authoritative sources and attribution
Identifiers and source titles belong to OWASP, MITRE, the CVE Program, CISA, NIST or the cited vendor. Source excerpts are attributed and adapted under the linked publisher license; editorial context is separate. This is not an official framework mirror. Review baseline: 2026-11-18. Live documents can change; check exact current applicability.
- Publisher reference: CWE-120 — source accessed 2026-11-18
- cwe — source accessed 2026-11-18
Source review supports bounded reference text. It is not execution evidence, a completeness claim, a CVSS assessment, a compliance certification or verification of production security.
