Security

What is Unchecked Return Value to NULL Pointer (CWE-690)?

Discover how unchecked return values can lead to NULL pointer dereferences, with real-world code examples and framework-specific fixes. Learn how to detect...

SP
Shreya Pillai July 29, 2026 5 min read Security

AI-friendly summary

AI-friendly summary

What it is: Unchecked Return Value to NULL Pointer Dereference (CWE-690) is a type of vulnerability where function return values are not checked, leading to potential null pointer dereferences.

Why it matters: This can cause system crashes and allow unauthorized execution or data corruption.

How to fix it: Always check function return values before using them.

TL;DR: Unchecked Return Value to NULL Pointer Dereference (CWE-690) is a critical vulnerability where unverified function returns lead to null pointer dereferences, causing crashes and data corruption. Fix by validating all return values.

Field Value
CWE ID CWE-690
OWASP Category Not directly mapped
CAPEC None known
Typical Severity Critical
Affected Technologies C/C++, Python, Java
Detection Difficulty Moderate
Last Updated 2026-07-29

What is Unchecked Return Value to NULL Pointer Dereference?

Unchecked Return Value to NULL Pointer Dereference (CWE-690) is a type of vulnerability where function return values are not checked, leading to potential null pointer dereferences. As defined by the MITRE Corporation under CWE-690 and classified by the OWASP Foundation under Security Misconfiguration.

Quick Summary

Unchecked Return Value to NULL Pointer Dereference can cause system crashes and allow unauthorized execution or data corruption. It is critical for developers to validate function return values before using them to prevent such issues. Jump to: Overview · Attack Scenario · Business Impact · Detection · Fix

Jump to: What is Unchecked Return Value to NULL Pointer Dereference? · Quick Summary · Unchecked Return Value to NULL Pointer Dereference Overview · How Unchecked Return Value to NULL Pointer Dereference Works · Business Impact of Unchecked Return Value to NULL Pointer Dereference · Unchecked Return Value to NULL Pointer Dereference Attack Scenario · How to Detect Unchecked Return Value to NULL Pointer Dereference · How to Fix Unchecked Return Value to NULL Pointer Dereference · Framework-Specific Fixes for Unchecked Return Value to NULL Pointer Dereference · How to Ask AI to Check Your Code for Unchecked Return Value to NULL Pointer Dereference · Unchecked Return Value to NULL Pointer Dereference Best Practices Checklist · Unchecked Return Value to NULL Pointer Dereference FAQ · Vulnerabilities Related to Unchecked Return Value to NULL Pointer Dereference · References · Scan Your Own Site

Unchecked Return Value to NULL Pointer Dereference Overview

What: A vulnerability where a function’s failure condition returns a null pointer without proper validation. Why it matters: It can lead to system crashes, unauthorized execution, and data corruption. Where it occurs: In applications that call functions which may return null pointers due to failures. Who is affected: Developers using languages like C/C++, Python, Java where function return values are not checked. Who is NOT affected: Applications with robust error handling mechanisms in place.

How Unchecked Return Value to NULL Pointer Dereference Works

Root Cause

The root cause is the failure of a function to properly validate its return value before using it. This can lead to null pointer dereferences, causing crashes and other security issues.

Attack Flow

  1. A function returns a NULL pointer due to an error condition.
  2. The caller does not check this return value.
  3. Dereferencing the NULL pointer leads to unexpected behavior or crash.
  4. Exploitation may result in unauthorized code execution or data corruption.

    Prerequisites to Exploit

    • Function must be able to return a NULL pointer on failure.
    • Caller must use the returned value without checking for NULL.
    • System must not have proper error handling mechanisms in place.

      Vulnerable Code

      void processFile(char* filename) {
       FILE *file = fopen(filename, "r");
       // Use file here...
      }
      

      This code is vulnerable because it does not check if fopen returned a NULL pointer before using the file handle.

Secure Code

void processFile(char* filename) {
    FILE *file = fopen(filename, "r");
    if (file == NULL) {
        // Handle error appropriately
        return;
    }
    // Use file here...
}

The secure code checks for a NULL pointer before using the file handle.

Business Impact of Unchecked Return Value to NULL Pointer Dereference

Availability: System crashes due to null pointer dereferences can disrupt service availability.

  • Example: A web application may crash, leading to downtime.
  • Consequences: Financial losses from lost transactions and customer dissatisfaction.

Integrity: Unauthorized execution or data corruption can compromise system integrity.

  • Example: An attacker could execute arbitrary code through a null pointer dereference.
  • Consequences: Data breaches leading to legal liabilities and reputational damage.

Unchecked Return Value to NULL Pointer Dereference Attack Scenario

  1. The attacker identifies a function that may return a NULL pointer on failure.
  2. They exploit this by triggering the error condition and causing the function to return NULL.
  3. The caller uses the returned value without checking, leading to a null pointer dereference.
  4. This causes unexpected behavior or crashes the system.
  5. Exploitation results in unauthorized execution of code.

How to Detect Unchecked Return Value to NULL Pointer Dereference

Manual Testing

  • Check if function return values are properly validated before use.
  • Look for calls to functions that may return NULL pointers without checks.
  • Verify error handling mechanisms are in place.
  • Test with various inputs to ensure proper behavior on failure conditions.

Automated Scanners (SAST/DAST)

Static analysis can detect code patterns indicative of unchecked return values. Dynamic testing is required to validate actual runtime behavior and edge cases.

PenScan Detection

PenScan’s scanner engines like ZAP, Nuclei, Wapiti, Nikto, SSLyze, Dalfox, and Nmap can identify potential CWE-690 vulnerabilities in code.

False Positive Guidance

A false positive may occur if the function returns NULL but is handled correctly elsewhere. Ensure proper validation before use to avoid such cases.

How to Fix Unchecked Return Value to NULL Pointer Dereference

  • Always check return values for NULL pointers before using them.
  • Implement robust error handling mechanisms.
  • Use defensive programming techniques to prevent null pointer dereferences.
  • Validate function inputs and outputs thoroughly.

Framework-Specific Fixes for Unchecked Return Value to NULL Pointer Dereference

C/C++

void processFile(char* filename) {
    FILE *file = fopen(filename, "r");
    if (file == NULL) {
        // Handle error appropriately
        return;
    }
    // Use file here...
}

This example shows proper validation of the fopen function’s return value before proceeding.

How to Ask AI to Check Your Code for Unchecked Return Value to NULL Pointer Dereference

Copy-paste prompt

Review the following C code block for potential CWE-690 Unchecked Return Value to NULL Pointer Dereference vulnerabilities and rewrite it using proper error handling: [paste code here]

Unchecked Return Value to NULL Pointer Dereference Best Practices Checklist

✅ Always check function return values before proceeding. ✅ Implement robust error handling mechanisms. ✅ Use defensive programming techniques to prevent null pointer dereferences. ✅ Validate function inputs and outputs thoroughly. ✅ Test with various edge cases to ensure proper behavior on failure conditions.

Unchecked Return Value to NULL Pointer Dereference FAQ

How does unchecked return value lead to a null pointer dereference?

When a function returns a NULL pointer due to failure, and the caller fails to check it before using it, a NULL pointer dereference occurs.

Can you provide an example of code that causes this vulnerability?

A common example is calling a function that may return a NULL pointer without checking its return value before dereferencing it.

What are the consequences if this vulnerability is exploited?

Exploitation can lead to crashes, unauthorized execution, and data corruption, compromising system availability and integrity.

How does PenScan detect Unchecked Return Value to NULL Pointer Dereference vulnerabilities?

PenScan uses static analysis tools like ZAP and Nuclei to identify code patterns indicative of this vulnerability.

What are the best practices for preventing unchecked return values in Python applications?

Always check function return values, especially those that can indicate failure by returning NULL pointers.

How does OWASP recommend mitigating this issue?

OWASP recommends thorough validation and error handling of function returns to prevent dereferencing null pointers.

What are the common prerequisites for exploiting Unchecked Return Value to NULL Pointer Dereference?

Exploitation requires a failure condition in a function that can return a NULL pointer without proper checks.

| CWE | Name | Relationship | |—|—|—| | CWE-252 | Unchecked Return Value | StartsWith |

References

Scan Your Own Site

Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Unchecked Return Value to NULL Pointer Dereference and other risks before an attacker does.