CWE-170 / WEAKNESS
Improper Null Termination
The product does not terminate or incorrectly terminates a string or array with a null character or equivalent terminator.
- Category
- CWE weaknesses
- Version / scope
- CWE 5.0; release 2026-10-28; publisher status Incomplete
- Affected / relevant technologies
- C / C++
- 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
Review publisher context and local applicability; this reference is not execution evidence.
Potential impact
Confidentiality Integrity Availability Read Memory Execute Unauthorized Code or Commands The case of an omitted null character is the most dangerous of the possible issues. This will almost certainly result in information disclosure, and possibly a buffer overflow condition, which may be exploited to execute arbitrary code. Confidentiality Integrity Availability DoS: Crash, Exit, or Restart Read Memory DoS: Resource Consumption (CPU) DoS: Resource Consumption (Memory) If a null character is omitted from a string, then most string-copying functions will read data until they locate a null character, even outside of the intended boundaries of the string. This could: cause a crash due to a segmentation fault cause sensitive adjacent memory to be copied and sent to an outsider trigger a buffer overflow when the copy is being written to a fixed-size buffer. Integrity Availability Modify Memory DoS: Crash, Exit, or Restart Misplaced null characters may result in any number of security problems. The biggest issue is a subset of buffer overflow, and write-what-where conditions, where data corruption occurs from the writing of a null character over valid data, or even instructions. A randomly placed null character may put the system into an undefined state, and therefore make it prone to crashing. A misplaced null character may corrupt other data in memory. Integrity Confidentiality Availability Access Control Other Alter Execution Logic Execute Unauthorized Code or Commands Should the null character corrupt the process flow, or affect a flag controlling access, it may lead to […]
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 5.0. Source checked: 2026-11-26.
Source object: CWE-170. Object modified: 2026-10-28.
Attribution and source terms (© The MITRE Corporation; reproduced with permission)Detection and investigation
- Automated Static Analysis Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.) High
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 Use a language that is not susceptible to these issues. However, be careful of null byte interaction errors (CWE-626) with lower-level constructs that may be written in a language that is susceptible.
- Implementation Ensure that all string functions used are understood fully as to how they append null characters. Also, be wary of off-by-one errors when appending nulls to the end of strings.
- Implementation If performance constraints permit, special code can be added that validates null-termination of string buffers, this is a rather naive and error-prone solution.
- Implementation Switch to bounded string manipulation functions. Inspect buffer lengths involved in the buffer overrun trace reported with the defect.
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.
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.
- CWE-170 → CanPrecede → CWE-120 Open related reference
- CWE-170 → CanPrecede → CWE-126 Open related reference
- CWE-170 → CanAlsoBe → CWE-147 Open related reference
- CWE-170 → ChildOf → CWE-20 Open related reference
- CWE-170 → PeerOf → CWE-463 Open related reference
- CWE-170 → PeerOf → CWE-464 Open related reference
- CWE-170 → PeerOf → CWE-573 Open related reference
- CWE-170 → ChildOf → CWE-707 Open related reference
- CWE-193 → CanPrecede → CWE-170 Open related reference
- CWE-682 → CanPrecede → CWE-170 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.
- https://cwe.mitre.org/data/definitions/170.html — Publisher link; not separately HTTP-checked
- MITRE CWE 5.0 source snapshot — source accessed 2026-11-26
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.
