CWE-252: Unchecked Return Value
The product does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions.
Last updated
The product does not check the return value from a method or function, which can prevent it from detecting unexpected states and conditions.
Last updated
Two common programmer assumptions are "this function call can never fail" and "it doesn't matter if this function call fails". If an attacker can force the function to fail or otherwise return a value that is not expected, then the subsequent program logic could lead to a vulnerability, because the product is not in a state that the programmer assumes. For example, if the program calls a function to drop privileges but does not check the return code to ensure that privileges were successfully dropped, then the program will continue to operate with the higher privileges.
Many functions will return some value about the success of their actions. This will alert the program whether or not to handle any errors caused by that function.
164 recorded CVEs are caused by CWE-252 (Unchecked Return Value). The highest-severity and most recent are shown first. 42 new CWE-252 CVEs have been recorded so far in 2026 (17 in 2025).
crypto: safexcel - Add error handling for dma_map_sg() calls
Unchecked Return Value in xcb
WatchGuard AuthPoint Gateway Improper Authentication Allows Unauthenticated Denial of Service
Apache Traffic Server: Server process can fail to drop privilege
iccDEV has heap-buffer-overflow in CIccCLUT::Init() at IccProfLib/IccTagLut.cpp
Showing 12 of 164 recorded CWE-252 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsWhat can happen when CWE-252 is exploited.
Unexpected State, DoS: Crash, Exit, or Restart
Affects: Availability, Integrity
An unexpected return value could place the system in a state that could lead to a crash or other unintended behaviors.
Typically introduced during these phases of the software lifecycle.
Practical mitigations for CWE-252, grouped by where in the lifecycle they apply.
Check the results of all functions that return a value and verify that the value is expected.
Effectiveness: High — Checking the return value of the function will typically be sufficient, however beware of race conditions (CWE-362) in a concurrent environment.
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 [7].
Ensure that you account for all possible return values from the function.
When designing a function, make sure you return a value or throw an exception in case of an error.
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
MITRE examples of the weakness in code.
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().
In the following example, it is possible to request that memcpy move a much larger segment of memory than assumed:
Vulnerable example
int returnChunkSize(void *) {
/* if chunk info is valid, return the size of usable memory,
* else, return -1 to indicate an error
*/
...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).
The following code does not check to see if memory allocation succeeded before attempting to use the pointer returned by malloc().
Vulnerable example
buf = (char*) malloc(req_size);The following examples read a file into a byte array.
Vulnerable example
char[] byteArray = new char[1024];
String userName = (String) i.Current();Vulnerable example
FileInputStream fis;
String userName = (String) i.next();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.
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.
Vulnerable example
String itemName = request.getParameter(ITEM_NAME);
...Vulnerable example
String itemName = request.Item(ITEM_NAME);
...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.
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.
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.
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.
Vulnerable example
void host_lookup(char *user_supplied_addr){
struct hostent *hp;
/*routine that ensures user_supplied_addr is in the right format for conversion */The following function attempts to acquire a lock in order to perform operations on a shared resource.
Vulnerable example
void f(pthread_mutex_t *mutex) {
pthread_mutex_lock(mutex);
/* access shared resource */Safe example
int f(pthread_mutex_t *mutex) {
int result;
/* access shared resource */
return result;Real CVEs that MITRE cites as examples of this weakness.
Common questions about CWE-252.
Weakness data is sourced from the MITRE CWE catalog (v4.20). CVE associations are aggregated and kept current by RadicalNotion.AI.
Get an alert when a new CWE-252 CVE affects your products, with AI-written analysis and remediation steps.