| Impact | Details |
|---|---|
|
Unexpected State; DoS: Crash, Exit, or Restart |
Scope: Availability, Integrity
An unexpected return value could place the system in a state that could lead to a crash or other unintended behaviors.
|
| Phase(s) | Mitigation |
|---|---|
|
Implementation |
Check the results of all functions that return a value and verify that the value is expected.
Effectiveness: High Note:
Checking the return value of the function will typically be sufficient, however beware of race conditions (CWE-362) in a concurrent environment.
|
|
Implementation |
For any pointers that could have been modified or provided from a function that can return NULL, check the pointer for NULL before use. When working with a multithreaded or otherwise asynchronous environment, ensure that proper locking APIs are used to lock before the check, and unlock when it has finished [REF-1484].
|
|
Implementation |
Ensure that you account for all possible return values from the function.
|
|
Implementation |
When designing a function, make sure you return a value or throw an exception in case of an error.
|
| 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. | 754 | Improper Check for Unusual or Exceptional Conditions |
| ParentOf | Chain Chain - a Compound Element that is a sequence of two or more separate weaknesses that can be closely linked together within software. One weakness, X, can directly create the conditions that are necessary to cause another weakness, Y, to enter a vulnerable condition. When this happens, CWE refers to X as "primary" to Y, and Y is "resultant" from X. Chains can involve more than two weaknesses, and in some cases, they might have a tree-like structure. | 690 | Unchecked Return Value to NULL Pointer Dereference |
| 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. | 273 | Improper Check for Dropped Privileges |
| 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. | 476 | NULL Pointer Dereference |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | Category Category - a CWE entry that contains a set of other entries that share a common characteristic. | 389 | Error Conditions, Return Values, Status Codes |
| 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. | 754 | Improper Check for Unusual or Exceptional Conditions |
| Phase | Note |
|---|---|
| Implementation |
Class: Not Language-Specific (Undetermined Prevalence)
Example 1
Consider the following code segment:
The programmer expects that when fgets() returns, buf will contain a null-terminated string of length 9 or less. But if an I/O error occurs, fgets() will not null-terminate buf. Furthermore, if the end of the file is reached before any characters are read, fgets() returns without writing anything to buf. In both of these situations, fgets() signals that something unusual has happened by returning NULL, but in this code, the warning will not be noticed. The lack of a null terminator in buf can result in a buffer overflow in the subsequent call to strcpy().
Example 2
In the following example, it is possible to request that memcpy move a much larger segment of memory than assumed:
If returnChunkSize() happens to encounter an error it will return -1. Notice that the return value is not checked before the memcpy operation (CWE-252), so -1 can be passed as the size argument to memcpy() (CWE-805). Because memcpy() assumes that the value is unsigned, it will be interpreted as MAXINT-1 (CWE-195), and therefore will copy far more memory than is likely available to the destination buffer (CWE-787, CWE-788).
Example 3
The following code does not check to see if memory allocation succeeded before attempting to use the pointer returned by malloc().
The traditional defense of this coding error is: "If my program runs out of memory, it will fail. It doesn't matter whether I handle the error or allow the program to die with a segmentation fault when it tries to dereference the null pointer." This argument ignores three important considerations:
Example 4
The following examples read a file into a byte array.
The code loops through a set of users, reading a private data file for each user. The programmer assumes that the files are always 1 kilobyte in size and therefore ignores the return value from Read(). If an attacker can create a smaller file, the program will recycle the remainder of the data from the previous user and treat it as though it belongs to the attacker.
Example 5
The following code does not check to see if the string returned by getParameter() is null before calling the member function compareTo(), potentially causing a NULL dereference.
The following code does not check to see if the string returned by the Item property is null before calling the member function Equals(), potentially causing a NULL dereference.
The traditional defense of this coding error is: "I know the requested value will always exist because.... If it does not exist, the program cannot perform the desired behavior so it doesn't matter whether I handle the error or allow the program to die dereferencing a null value." But attackers are skilled at finding unexpected paths through programs, particularly when exceptions are involved.
Example 6
The following code shows a system property that is set to null and later dereferenced by a programmer who mistakenly assumes it will always be defined.
The traditional defense of this coding error is: "I know the requested value will always exist because.... If it does not exist, the program cannot perform the desired behavior so it doesn't matter whether I handle the error or allow the program to die dereferencing a null value." But attackers are skilled at finding unexpected paths through programs, particularly when exceptions are involved.
Example 7
The following VB.NET code does not check to make sure that it has read 50 bytes from myfile.txt. This can cause DoDangerousOperation() to operate on an unexpected value.
In .NET, it is not uncommon for programmers to misunderstand Read() and related methods that are part of many System.IO classes. The stream and reader classes do not consider it to be unusual or exceptional if only a small amount of data becomes available. These classes simply add the small amount of data to the return buffer, and set the return value to the number of bytes or characters read. There is no guarantee that the amount of data returned is equal to the amount of data requested.
Example 8
It is not uncommon for Java programmers to misunderstand read() and related methods that are part of many java.io classes. Most errors and unusual events in Java result in an exception being thrown. But the stream and reader classes do not consider it unusual or exceptional if only a small amount of data becomes available. These classes simply add the small amount of data to the return buffer, and set the return value to the number of bytes or characters read. There is no guarantee that the amount of data returned is equal to the amount of data requested. This behavior makes it important for programmers to examine the return value from read() and other IO methods to ensure that they receive the amount of data they expect.
Example 9
This example takes an IP address from a user, verifies that it is well formed and then looks up the hostname and copies it into a buffer.
If an attacker provides an address that appears to be well-formed, but the address does not resolve to a hostname, then the call to gethostbyaddr() will return NULL. Since the code does not check the return value from gethostbyaddr (CWE-252), a NULL pointer dereference (CWE-476) would then occur in the call to strcpy().
Note that this code is also vulnerable to a buffer overflow (CWE-119).
Example 10
The following function attempts to acquire a lock in order to perform operations on a shared resource.
However, the code does not check the value returned by pthread_mutex_lock() for errors. If pthread_mutex_lock() cannot acquire the mutex for any reason, the function may introduce a race condition into the program and result in undefined behavior.
In order to avoid data races, correctly written programs must check the result of thread synchronization functions and appropriately handle all errors, either by attempting to recover from them or reporting them to higher levels.
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 |
|---|---|
|
Unchecked return value leads to resultant integer overflow and code execution.
|
|
|
Program does not check return value when invoking functions to drop privileges, which could leave users with higher privileges than expected by forcing those functions to fail.
|
|
|
Program does not check return value when invoking functions to drop privileges, which could leave users with higher privileges than expected by forcing those functions to fail.
|
|
|
chain: unchecked return value can lead to NULL dereference
|
|
|
Linux-based device mapper encryption program does not check the return value of setuid and setgid allowing attackers to execute code with unintended privileges.
|
|
| Ordinality | Description |
|---|---|
|
Primary
|
(where the weakness exists independent of 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. | 227 | 7PK - API Abuse |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 728 | OWASP Top Ten 2004 Category A7 - Improper Error Handling |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 742 | CERT C Secure Coding Standard (2008) Chapter 9 - Memory Management (MEM) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 847 | The CERT Oracle Secure Coding Standard for Java (2011) Chapter 4 - Expressions (EXP) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 876 | CERT C++ Secure Coding Section 08 - Memory Management (MEM) |
| 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. | 962 | SFP Secondary Cluster: Unchecked Status Condition |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1129 | CISQ Quality Measures (2016) - Reliability |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1131 | CISQ Quality Measures (2016) - Security |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1136 | SEI CERT Oracle Secure Coding Standard for Java - Guidelines 02. Expressions (EXP) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1167 | SEI CERT C Coding Standard - Guidelines 12. Error Handling (ERR) |
| 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. | 1181 | SEI CERT Perl Coding Standard - Guidelines 03. Expressions (EXP) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1306 | CISQ Quality Measures - Reliability |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1308 | CISQ Quality Measures - Security |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1405 | Comprehensive Categorization: Improper Check or Handling of Exceptional Conditions |
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.| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| 7 Pernicious Kingdoms | Unchecked Return Value | ||
| CLASP | Ignored function return value | ||
| OWASP Top Ten 2004 | A7 | CWE More Specific | Improper Error Handling |
| CERT C Secure Coding | ERR33-C | Imprecise | Detect and handle standard library errors |
| CERT C Secure Coding | POS54-C | Imprecise | Detect and handle POSIX library errors |
| The CERT Oracle Secure Coding Standard for Java (2011) | EXP00-J | Do not ignore values returned by methods | |
| SEI CERT Perl Coding Standard | EXP32-PL | Exact | Do not ignore function return values |
| Software Fault Patterns | SFP4 | Unchecked Status Condition | |
| OMG ASCSM | ASCSM-CWE-252-resource | ||
| OMG ASCRM | ASCRM-CWE-252-data | ||
| OMG ASCRM | ASCRM-CWE-252-resource |
| Submissions | ||
|---|---|---|
| Submission Date | Submitter | Organization |
|
2006年07月19日
(CWE Draft 3, 2006年07月19日) |
7 Pernicious Kingdoms | |
| Contributions | ||
| Contribution Date | Contributor | Organization |
| 2010年04月30日 | Martin Sebor | Cisco Systems, Inc. |
| Provided Demonstrative Example and suggested CERT reference | ||
| Modifications | ||
| Modification Date | Modifier | Organization |
|
2025年09月09日
(CWE 4.18, 2025年09月09日) |
CWE Content Team | MITRE |
| updated Potential_Mitigations, References | ||
| 2023年10月26日 | CWE Content Team | MITRE |
| updated Observed_Examples | ||
| 2023年06月29日 | CWE Content Team | MITRE |
| updated Mapping_Notes, Relationships | ||
| 2023年04月27日 | CWE Content Team | MITRE |
| updated Detection_Factors, Relationships | ||
| 2023年01月31日 | CWE Content Team | MITRE |
| updated Description | ||
| 2021年07月20日 | CWE Content Team | MITRE |
| updated Observed_Examples | ||
| 2021年03月15日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples, Observed_Examples, Relationships, Weakness_Ordinalities | ||
| 2020年08月20日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2020年06月25日 | CWE Content Team | MITRE |
| updated Observed_Examples | ||
| 2020年02月24日 | CWE Content Team | MITRE |
| updated References | ||
| 2019年06月20日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2019年01月03日 | CWE Content Team | MITRE |
| updated References, Relationships, Taxonomy_Mappings | ||
| 2018年03月27日 | CWE Content Team | MITRE |
| updated References | ||
| 2017年11月08日 | CWE Content Team | MITRE |
| updated Applicable_Platforms, References, Relationships, Taxonomy_Mappings | ||
| 2014年07月30日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples, Relationships, Taxonomy_Mappings | ||
| 2014年06月23日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples, Potential_Mitigations | ||
| 2012年05月11日 | CWE Content Team | MITRE |
| updated Common_Consequences, References, Relationships | ||
| 2011年09月13日 | CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
| 2011年06月27日 | CWE Content Team | MITRE |
| updated Common_Consequences | ||
| 2011年06月01日 | CWE Content Team | MITRE |
| updated Common_Consequences, Demonstrative_Examples, Relationships, Taxonomy_Mappings | ||
| 2010年12月13日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples | ||
| 2010年09月27日 | CWE Content Team | MITRE |
| updated Observed_Examples | ||
| 2010年06月21日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples, References | ||
| 2010年04月05日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples | ||
| 2010年02月16日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples, Potential_Mitigations, References | ||
| 2009年12月28日 | CWE Content Team | MITRE |
| updated Common_Consequences, Demonstrative_Examples, References | ||
| 2009年07月27日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples | ||
| 2009年05月27日 | CWE Content Team | MITRE |
| updated Demonstrative_Examples | ||
| 2009年03月10日 | CWE Content Team | MITRE |
| updated Relationships | ||
| 2009年01月12日 | CWE Content Team | MITRE |
| updated Background_Details, Demonstrative_Examples, Description, Observed_Examples, Other_Notes, Potential_Mitigations | ||
| 2008年11月24日 | CWE Content Team | MITRE |
| updated Relationships, Taxonomy_Mappings | ||
| 2008年09月08日 | CWE Content Team | MITRE |
| updated Common_Consequences, Relationships, Other_Notes, Taxonomy_Mappings | ||
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.