---
title: "CWE-252: Unchecked Return Value"
url: https://radicalnotion.ai/cwe/cwe-252
type: cwe
description: "The product does not check the return value from a method or function."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-252: Unchecked Return Value

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** Low
- **CVEs with this as primary weakness:** 239
- **Of those, in CISA KEV:** 0
- **New in 2026:** 89
- **CWE catalog version:** 4.21

## Description

The product does not check the return value from a method or function.

## Background

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.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | 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. |

## Applicable platforms

**Languages:** Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability, Integrity | Unexpected State, Varies by Context, DoS: Crash, Exit, or Restart | The product could be prevented from detecting unexpected states and conditions, placing the product into a state that could lead to a crash or other unintended behaviors. |
| Access Control | Bypass Protection Mechanism | If the method/function is used for a protection mechanism, then an unchecked return value could prevent the code from being able to see if the protection mechanism fails. 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. |

## Potential mitigations

### Implementation

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.

### 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.

## Detection methods

### 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

## Demonstrative examples

### Example 1

Consider the following code segment:

Bad code:

```c
char buf[10], cp_buf[10];
fgets(buf, 10, stdin);
strcpy(cp_buf, buf);
```

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:

Bad code:

```c
int returnChunkSize(void *) {

    /* if chunk info is valid, return the size of usable memory,

    * else, return -1 to indicate an error

    */
    ...
}
int main() {
    ...
    memcpy(destBuf, srcBuf, (returnChunkSize(destBuf)-1));
    ...
}
```

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().

Bad code:

```c
buf = (char*) malloc(req_size);
strncpy(buf, xfer, req_size);
```

### Example 4

The following examples read a file into a byte array.

Bad code:

```c#
char[] byteArray = new char[1024];
for (IEnumerator i=users.GetEnumerator(); i.MoveNext() ;i.Current()) {
    String userName = (String) i.Current();
    String pFileName = PFILE_ROOT + "/" + userName;
    StreamReader sr = new StreamReader(pFileName);
    sr.Read(byteArray,0,1024);//the file is always 1k bytes
    sr.Close();
    processPFile(userName, byteArray);
}
```

Bad code:

```java
FileInputStream fis;
byte[] byteArray = new byte[1024];
for (Iterator i=users.iterator(); i.hasNext();) {
    String userName = (String) i.next();
    String pFileName = PFILE_ROOT + "/" + userName;
    FileInputStream fis = new FileInputStream(pFileName);
    fis.read(byteArray); // the file is always 1k bytes
    fis.close();
    processPFile(userName, byteArray);
```

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.

Bad code:

```java
String itemName = request.getParameter(ITEM_NAME);
if (itemName.compareTo(IMPORTANT_ITEM) == 0) {
    ...
}
...
```

Bad code:

```java
String itemName = request.Item(ITEM_NAME);
if (itemName.Equals(IMPORTANT_ITEM)) {
    ...
}
...
```

### 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.

Bad code:

```java
System.clearProperty("os.name");
...
String os = System.getProperty("os.name");
if (os.equalsIgnoreCase("Windows 95")) System.out.println("Not supported");
```

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.

Bad code:

```c#
Dim MyFile As New FileStream("myfile.txt", FileMode.Open, FileAccess.Read, FileShare.Read)
Dim MyArray(50) As Byte
MyFile.Read(MyArray, 0, 50)
DoDangerousOperation(MyArray(20))
```

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.

Bad code:

```c
void host_lookup(char *user_supplied_addr){
    struct hostent *hp;
    in_addr_t *addr;
    char hostname[64];
    in_addr_t inet_addr(const char *cp);

    /*routine that ensures user_supplied_addr is in the right format for conversion */

    validate_addr_form(user_supplied_addr);
    addr = inet_addr(user_supplied_addr);
    hp = gethostbyaddr( addr, sizeof(struct in_addr), AF_INET);
    strcpy(hostname, hp->h_name);
}
```

### Example 10

The following function attempts to acquire a lock in order to perform operations on a shared resource.

Bad code:

```c
void f(pthread_mutex_t *mutex) {
    pthread_mutex_lock(mutex);

    /* access shared resource */

    pthread_mutex_unlock(mutex);
}
```

Good code:

```c
int f(pthread_mutex_t *mutex) {
    int result;

    result = pthread_mutex_lock(mutex);
    if (0 != result)
        return result;

    /* access shared resource */

    return pthread_mutex_unlock(mutex);
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2020-17533 | Chain: unchecked return value (CWE-252) of some functions for policy enforcement leads to authorization bypass (CWE-862) |
| CVE-2020-6078 | Chain: The return value of a function returning a pointer is not checked for success (CWE-252) resulting in the later use of an uninitialized variable (CWE-456) and a null pointer dereference (CWE-476) |
| CVE-2019-15900 | Chain: sscanf() call is used to check if a username and group exists, but the return value of sscanf() call is not checked (CWE-252), causing an uninitialized variable to be checked (CWE-457), returning success to allow authorization bypass for executing a privileged (CWE-863). |
| CVE-2007-3798 | Unchecked return value leads to resultant integer overflow and code execution. |
| CVE-2006-4447 | 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. |
| CVE-2006-2916 | 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. |
| CVE-2008-5183 | Chain: unchecked return value can lead to NULL dereference |
| CVE-2010-0211 | Chain: unchecked return value (CWE-252) leads to free of invalid, uninitialized pointer (CWE-824). |
| CVE-2017-6964 | Linux-based device mapper encryption program does not check the return value of setuid and setgid allowing attackers to execute code with unintended privileges. |
| CVE-2002-1372 | Chain: Return values of file/socket operations are not checked (CWE-252), allowing resultant consumption of file descriptors (CWE-772). |

## Real CVEs with this weakness (sample of 12 of 239)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-126708 | Unchecked PKCS5\_PBKDF2\_HMAC() return can authenticate any password | critical | 9.8 | - | No | 2026-11-18 |
| CVE-2023-52687 | crypto: safexcel - Add error handling for dma\_map\_sg() calls | critical | 9.8 | - | No | 2024-05-17 |
| CVE-2022-25718 | - | critical | 9.8 | - | No | 2022-10-19 |
| CVE-2021-38171 | - | critical | 9.8 | - | No | 2021-08-21 |
| CVE-2021-26955 | Unchecked Return Value in xcb | critical | 9.8 | - | No | 2021-02-09 |
| CVE-1999-0199 | glibc: manual/search.texi lacks a statement about the unspecified tdelete return value upon deletion of a tree's root | critical | 9.8 | - | No | 2020-10-06 |
| CVE-2019-15900 | - | critical | 9.8 | - | No | 2019-10-18 |
| CVE-2010-0211 | openldap: modrdn processing uninitialized pointer free | critical | 9.8 | - | No | 2010-07-27 |
| CVE-2007-3798 | tcpdump BGP integer overflow | critical | 9.8 | - | No | 2007-07-16 |
| CVE-2025-66565 | Fiber Utils UUIDv4 and UUID Silent Fallback to Predictable Values | critical | 9.3 | - | No | 2025-12-09 |
| CVE-2026-121639 | WatchGuard AuthPoint Gateway Improper Authentication Allows Unauthenticated Denial of Service | critical | 9.2 | - | No | 2026-11-04 |
| CVE-2026-72496 | RDMA/bnxt\_re: Proper rollback if the ioremap fails | critical | 9.2 | - | No | 2026-08-15 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-754](https://radicalnotion.ai/cwe/cwe-754) | Improper Check for Unusual or Exceptional Conditions |
| Child | [CWE-690](https://radicalnotion.ai/cwe/cwe-690) | Unchecked Return Value to NULL Pointer Dereference |
| Peer | [CWE-273](https://radicalnotion.ai/cwe/cwe-273) | Improper Check for Dropped Privileges |
| Can precede | [CWE-476](https://radicalnotion.ai/cwe/cwe-476) | NULL Pointer Dereference |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| 7 Pernicious Kingdoms | Unchecked Return Value | - | - |
| CLASP | Ignored function return value | - | - |
| OWASP Top Ten 2004 | Improper Error Handling | A7 | CWE More Specific |
| CERT C Secure Coding | Detect and handle standard library errors | ERR33-C | Imprecise |
| CERT C Secure Coding | Detect and handle POSIX library errors | POS54-C | Imprecise |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not ignore values returned by methods | EXP00-J | - |
| SEI CERT Perl Coding Standard | Do not ignore function return values | EXP32-PL | Exact |
| Software Fault Patterns | Unchecked Status Condition | SFP4 | - |
| OMG ASCSM | - | ASCSM-CWE-252-resource | - |
| OMG ASCRM | - | ASCRM-CWE-252-data | - |
| OMG ASCRM | - | ASCRM-CWE-252-resource | - |
| OpenSSF Secure Coding Guide for Python | Check Return Values | pyscg-0036 | - |

## Frequently asked questions

### What is CWE-252?

The product does not check the return value from a method or function.

### What CVEs are caused by CWE-252?

239 recorded CVEs are attributed to CWE-252, including CVE-2026-126708, CVE-2023-52687 and CVE-2022-25718.

### Is CWE-252 part of the OWASP Top 10?

CWE-252 maps to OWASP Top Ten 2004: Improper Error Handling (A7) in the OWASP security taxonomy.

### How do you prevent CWE-252?

Check the results of all functions that return a value and verify that the value is expected.

### How is CWE-252 detected?

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.)

### What are the consequences of CWE-252?

Exploiting CWE-252 can lead to: Unexpected State, Varies by Context, DoS: Crash, Exit, or Restart, Bypass Protection Mechanism.

### Is CWE-252 actively exploited?

239 recorded CVEs are caused by CWE-252; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/252.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-252). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
