| Impact | Details |
|---|---|
|
Read Memory; Execute Unauthorized Code or Commands |
Scope: Confidentiality, Integrity, Availability
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.
|
|
DoS: Crash, Exit, or Restart; Read Memory; DoS: Resource Consumption (CPU); DoS: Resource Consumption (Memory) |
Scope: Confidentiality, Integrity, Availability
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.
|
|
Modify Memory; DoS: Crash, Exit, or Restart |
Scope: Integrity, Availability
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.
|
|
Alter Execution Logic; Execute Unauthorized Code or Commands |
Scope: Integrity, Confidentiality, Availability, Access Control, Other
Should the null character corrupt the process flow, or affect a flag controlling access, it may lead to logical errors which allow for the execution of arbitrary code.
|
| Phase(s) | Mitigation |
|---|---|
|
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.
|
|
Implementation |
Add code that fills buffers with nulls (however, the length of buffers still needs to be inspected, to ensure that the non null-terminated string is not written at the physical end of the buffer).
|
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Pillar Pillar - a weakness that is the most abstract type of weakness and represents a theme for all class/base/variant weaknesses related to it. A Pillar is different from a Category as a Pillar is still technically a type of weakness that describes a mistake, while a Category represents a common characteristic used to group related things. | 707 | Improper Neutralization |
| PeerOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 463 | Deletion of Data Structure Sentinel |
| PeerOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 464 | Addition of Data Structure Sentinel |
| CanAlsoBe | Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. | 147 | Improper Neutralization of Input Terminators |
| CanFollow | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 193 | Off-by-one Error |
| CanFollow | Pillar Pillar - a weakness that is the most abstract type of weakness and represents a theme for all class/base/variant weaknesses related to it. A Pillar is different from a Category as a Pillar is still technically a type of weakness that describes a mistake, while a Category represents a common characteristic used to group related things. | 682 | Incorrect Calculation |
| CanPrecede | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') |
| CanPrecede | Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. | 126 | Buffer Over-read |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | Category Category - a CWE entry that contains a set of other entries that share a common characteristic. | 137 | Data Neutralization Issues |
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Class Class - a weakness that is described in a very abstract fashion, typically independent of any specific language or technology. More specific than a Pillar Weakness, but more general than a Base Weakness. Class level weaknesses typically describe issues in terms of 1 or 2 of the following dimensions: behavior, property, and resource. | 20 | Improper Input Validation |
| Phase | Note |
|---|---|
| Implementation |
C (Undetermined Prevalence)
C++ (Undetermined Prevalence)
Example 1
The following code reads from cfgfile and copies the input into inputbuf using strcpy(). The code mistakenly assumes that inputbuf will always contain a NULL terminator.
The code above will behave correctly if the data read from cfgfile is null terminated on disk as expected. But if an attacker is able to modify this input so that it does not contain the expected NULL character, the call to strcpy() will continue copying from memory until it encounters an arbitrary NULL character. This will likely overflow the destination buffer and, if the attacker can control the contents of memory immediately following inputbuf, can leave the application susceptible to a buffer overflow attack.
Example 2
In the following code, readlink() expands the name of a symbolic link stored in pathname and puts the absolute path into buf. The length of the resulting value is then calculated using strlen().
The code above will not always behave correctly as readlink() does not append a NULL byte to buf. Readlink() will stop copying characters once the maximum size of buf has been reached to avoid overflowing the buffer, this will leave the value buf not NULL terminated. In this situation, strlen() will continue traversing memory until it encounters an arbitrary NULL character further on down the stack, resulting in a length value that is much larger than the size of string. Readlink() does return the number of bytes copied, but when this return value is the same as stated buf size (in this case MAXPATH), it is impossible to know whether the pathname is precisely that many bytes long, or whether readlink() has truncated the name to avoid overrunning the buffer. In testing, vulnerabilities like this one might not be caught because the unused contents of buf and the memory immediately following it may be NULL, thereby causing strlen() to appear as if it is behaving correctly.
Example 3
While the following example is not exploitable, it provides a good example of how nulls can be omitted or misplaced, even when "safe" functions are used:
The above code gives the following output: "The last character in shortString is: n (6e)". So, the shortString array does not end in a NULL character, even though the "safe" string function strncpy() was used. The reason is that strncpy() does not impliciitly add a NULL character at the end of the string when the source is equal in length or longer than the provided size.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
| Reference | Description |
|---|---|
|
Attacker does not null-terminate argv[] when invoking another program.
|
|
|
Interrupted step causes resultant lack of null termination.
|
|
|
Fault causes resultant lack of null termination, leading to buffer expansion.
|
|
|
Multiple vulnerabilities related to improper null termination.
|
|
|
Product does not null terminate a message buffer after snprintf-like call, leading to overflow.
|
|
| Ordinality | Description |
|---|---|
|
Resultant
|
(where the weakness is typically related to the presence of some other weaknesses)
|
| Method | Details |
|---|---|
|
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.)
Effectiveness: High |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 730 | OWASP Top Ten 2004 Category A9 - Denial of Service |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 741 | CERT C Secure Coding Standard (2008) Chapter 8 - Characters and Strings (STR) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 748 | CERT C Secure Coding Standard (2008) Appendix - POSIX (POS) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 875 | CERT C++ Secure Coding Section 07 - Characters and Strings (STR) |
| MemberOf | ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). | 884 | CWE Cross-section |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 973 | SFP Secondary Cluster: Improper NULL Termination |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1161 | SEI CERT C Coding Standard - Guidelines 07. Characters and Strings (STR) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1171 | SEI CERT C Coding Standard - Guidelines 50. POSIX (POS) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1306 | CISQ Quality Measures - Reliability |
| MemberOf | ViewView - a subset of CWE entries that provides a way of examining CWE content. The two main view structures are Slices (flat lists) and Graphs (containing relationships between entries). | 1340 | CISQ Data Protection Measures |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1407 | Comprehensive Categorization: Improper Neutralization |
Rationale
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.Comments
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.Relationship
Relationship
Applicable Platform
Conceptually, this does not just apply to the C language; any language or representation that involves a terminator could have this type of problem.
Maintenance
| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| PLOVER | Improper Null Termination | ||
| 7 Pernicious Kingdoms | String Termination Error | ||
| CLASP | Miscalculated null termination | ||
| OWASP Top Ten 2004 | A9 | CWE More Specific | Denial of Service |
| CERT C Secure Coding | POS30-C | CWE More Abstract | Use the readlink() function properly |
| CERT C Secure Coding | STR03-C | Do not inadvertently truncate a null-terminated byte string | |
| CERT C Secure Coding | STR32-C | Exact | Do not pass a non-null-terminated character sequence to a library function that expects a string |
| Software Fault Patterns | SFP11 | Improper Null Termination |
| Submissions | ||
|---|---|---|
| Submission Date | Submitter | Organization |
|
2006年07月19日
(CWE Draft 3, 2006年07月19日) |
PLOVER | |
| Modifications | ||
| Modification Date | Modifier | Organization |
| 2023年06月29日 | CWE Content Team | MITRE |
| updated Mapping_Notes | ||
| 2023年04月27日 | CWE Content Team | MITRE |
| updated Detection_Factors, Relationships | ||
| 2023年01月31日 | CWE Content Team | MITRE |
| updated Description | ||
| 2020年12月10日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2020年08月20日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2020年02月24日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2019年01月03日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2018年03月27日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples | ||
| 2017年11月08日 | CWE Content Team | MITRE |
| updated Causal_Nature, Observed_Examples, Relationships, Taxonomy_Mappings, White_Box_Definitions | ||
| 2014年07月30日 | CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
| 2014年06月23日 | CWE Content Team | MITRE |
| updated Observed_Examples | ||
| 2012年05月11日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2011年09月13日 | CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
| 2011年06月01日 | CWE Content Team | MITRE |
| updated Common_Consequences | ||
| 2011年03月29日 | CWE Content Team | MITRE |
| updated Common_Consequences | ||
| 2009年10月29日 | CWE Content Team | MITRE |
| updated Description | ||
| 2009年07月27日 | CWE Content Team | MITRE |
| updated Common_Consequences, Other_Notes, Potential_Mitigations, White_Box_Definitions | ||
| 2009年07月17日 | KDM Analytics | |
| Improved the White_Box_Definition | ||
| 2009年05月27日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples | ||
| 2009年03月10日 | CWE Content Team | MITRE |
| updated Common_Consequences | ||
| 2008年11月24日 | CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
| 2008年09月08日 | CWE Content Team | MITRE |
| updated Applicable_Platforms, Causal_Nature, Common_Consequences, Description, Likelihood_of_Exploit, Maintenance_Notes, Relationships, Other_Notes, Relationship_Notes, Taxonomy_Mappings, Weakness_Ordinalities | ||
| 2008年08月01日 | KDM Analytics | |
| added/updated white box definitions | ||
| 2008年07月01日 | Eric Dalci | Cigital |
| updated Time_of_Introduction | ||
Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2025, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.