CWE-690 Compound Draft

Unchecked Return Value to NULL Pointer Dereference

This vulnerability occurs when a program calls a function that can return a NULL pointer to signal failure, but the code does not check for this error condition before using the returned value,…

Definition

What is CWE-690?

This vulnerability occurs when a program calls a function that can return a NULL pointer to signal failure, but the code does not check for this error condition before using the returned value, leading to a crash or unexpected behavior from dereferencing the NULL pointer.
Many functions in C and similar languages use a NULL pointer return value to indicate that an operation failed, such as when memory allocation fails or a required resource isn't found. If a developer assumes the call was always successful and uses the return value directly—for example, by trying to read or write to that memory location—the program will attempt to dereference NULL, typically causing a segmentation fault and a crash. This is a specific and common case of a broader class of unchecked return value errors. While not all functions signal errors with NULL (some use special integers or status codes), the pattern of failing to validate a function's output before proceeding is a frequent source of instability. Properly handling these potential NULL returns by adding checks is a fundamental practice for writing robust and secure software that can gracefully manage unexpected states.
Auswirkungen in der Praxis

Real-world CVEs caused by CWE-690

  • Large Content-Length value leads to NULL pointer dereference when malloc fails.

  • Large message length field leads to NULL pointer dereference when malloc fails.

  • Parsing routine encounters NULL dereference when input is missing a colon separator.

  • URI parsing API sets argument to NULL when a parsing failure occurs, such as when the Referer header is missing a hostname, leading to NULL dereference.

  • chain: unchecked return value can lead to NULL dereference

Wie Angreifer es ausnutzen

Angreiferpfad Schritt für Schritt

  1. 1

    The code below makes a call to the getUserName() function but doesn't check the return value before dereferencing (which may cause a NullPointerException).

  2. 2

    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.

  3. 3

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

  4. 4

    Note that this code is also vulnerable to a buffer overflow (CWE-119).

Verwundbares Codebeispiel

Vulnerable Java

The code below makes a call to the getUserName() function but doesn't check the return value before dereferencing (which may cause a NullPointerException).

Verwundbar Java
String username = getUserName();
  if (username.equals(ADMIN_USER)) {
  	...
  }
Sicheres Codebeispiel

Secure pseudo

Sicher pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Präventions-Checkliste

How to prevent CWE-690

  • Architecture Use safe-by-default frameworks and APIs that prevent the unsafe pattern from being expressible.
  • Implementation Validate input at trust boundaries; use allowlists, not denylists.
  • Implementation Apply the principle of least privilege to credentials, file paths, and runtime permissions.
  • Testing Cover this weakness in CI: SAST rules + targeted unit tests for the data flow.
  • Operation Monitor logs for the runtime signals listed in the next section.
Erkennungssignale

How to detect CWE-690

Black Box

This typically occurs in rarely-triggered error conditions, reducing the chances of detection during black box testing.

White Box

Code analysis can require knowledge of API behaviors for library functions that might return NULL, reducing the chances of detection when unknown libraries are used.

Plexicus Auto-Fix

Plexicus erkennt CWE-690 automatisch und öffnet in unter 60 Sekunden einen Fix-PR.

Codex Remedium scannt jeden Commit, identifiziert genau diese Schwachstelle und liefert einen reviewer-ready Pull Request mit dem Patch. Keine Tickets. Keine Hand-offs.

Häufig gestellte Fragen

Frequently asked questions

Was ist CWE-690?

This vulnerability occurs when a program calls a function that can return a NULL pointer to signal failure, but the code does not check for this error condition before using the returned value, leading to a crash or unexpected behavior from dereferencing the NULL pointer.

Wie gravierend ist CWE-690?

MITRE hat für diese Schwachstelle keine Exploit-Wahrscheinlichkeit veröffentlicht. Behandle sie als mittlere Auswirkung, bis dein Threat Model anderes belegt.

Welche Sprachen oder Plattformen sind von CWE-690 betroffen?

MITRE lists the following affected platforms: C, C++.

Wie kann ich CWE-690 verhindern?

Use safe-by-default frameworks, validate untrusted input at trust boundaries, and apply the principle of least privilege. Cover the data-flow signature in CI with SAST.

Wie erkennt und behebt Plexicus CWE-690?

Die SAST-Engine von Plexicus erkennt die Datenfluss-Signatur von CWE-690 bei jedem Commit. Bei einem Treffer öffnet unser Codex-Remedium-Agent einen Fix-PR mit korrigiertem Code, Tests und einer einzeiligen Zusammenfassung für den Reviewer.

Wo erfahre ich mehr über CWE-690?

MITRE veröffentlicht die kanonische Definition unter https://cwe.mitre.org/data/definitions/690.html. Für ergänzende Hinweise kannst du auch die OWASP- und NIST-Dokumentation heranziehen.

Bereit, wenn du es bist

Schluss mit dem Bezahlen pro Entwickler.
Schließ den Kreislauf.

Plexicus ist die KI-native ASPM, die scannt, filtert, fixt, pentestet und erklärt — autonom. Unbegrenzte Entwickler, unbegrenzte Repos, Fair-Use-KI-Aktionen. Echter kostenloser Tarif, €269/mo jährlich, wenn du bereit bist.