CWE-476: NULL Pointer Dereference
Also known as: NPD, null deref, NPE, nil pointer dereference
The product dereferences a pointer that it expects to be valid but is NULL.
Last updated
Also known as: NPD, null deref, NPE, nil pointer dereference
The product dereferences a pointer that it expects to be valid but is NULL.
Last updated
CWE-476 (NULL Pointer Dereference) is a base-level software weakness catalogued by MITRE in the Common Weakness Enumeration (CWE). It describes a recurring type of mistake that can lead to exploitable security vulnerabilities.
6,608 recorded CVEs are caused by CWE-476 (NULL Pointer Dereference), including 1 in CISA's KEV (Known Exploited Vulnerabilities) catalog. KEVs are shown first. 1,800 new CWE-476 CVEs have been recorded so far in 2026 (1,345 in 2025).
Windows Remote Access Connection Manager Denial of Service Vulnerability
sctp: move SCTP_CMD_ASSOC_SHKEY right after SCTP_CMD_PEER_INIT
QEMU: rocker: NULL pointer dereference in of_dpa_cmd_add_l2_flood()
kernel: l2tp: Fix oops in pppol2tp_xmit
nfsd: don't modify a session slot when replaying its cached reply
scsi: libiscsi: Validate the ITT reflected in a Reject PDU
wifi: mac80211: abort chanswitch when leaving a mesh
ALSA: hda: trace PCM open only after assigning a stream
drm/amdgpu: check ras and obj before dereference
spi: Fix DMA mapping ownership on partial map failure
NFSD: Prevent lock owner use-after-free during client teardown
Showing 12 of 6,608 recorded CWE-476 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsWhat can happen when CWE-476 is exploited.
DoS: Crash, Exit, or Restart
Affects: Availability
NULL pointer dereferences usually result in the failure of the process unless exception handling (on some platforms) is available and implemented. Even when exception handling is being used, it can still be very difficult to return the software to a safe state of operation.
Execute Unauthorized Code or Commands, Read Memory, Modify Memory
Affects: Integrity, Confidentiality
In rare circumstances, when NULL is equivalent to the 0x0 memory address and privileged code can access it, then writing or reading memory is possible, which may lead to code execution.
Typically introduced during these phases of the software lifecycle.
Languages
Practical mitigations for CWE-476, grouped by where in the lifecycle they apply.
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 [6].
Select a programming language that is not susceptible to these issues.
Check the results of all functions that return a value and verify that the value is non-null before acting upon it.
Effectiveness: Moderate — Checking the return value of the function will typically be sufficient, however beware of race conditions (CWE-362) in a concurrent environment. This solution does not handle the use of improperly initialized variables (CWE-665).
Identify all variables and data stores that receive information from external sources, and apply input validation to make sure that they are only initialized to expected values.
Explicitly initialize all variables and other data stores, either during declaration or just before the first usage.
This weakness can be detected using dynamic tools and techniques that interact with the software using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The software's operation may slow down, but it should not become unstable, crash, or generate incorrect results.
Effectiveness: Moderate
Identify error conditions that are not likely to occur during normal usage and trigger them. For example, run the program under low memory conditions, run with insufficient privileges or permissions, interrupt a transaction before it is completed, or disable connectivity to basic network services such as DNS. Monitor the software for any unexpected behavior. If you trigger an unhandled exception or similar error that was discovered and handled by the application's environment, it may still indicate unexpected conditions that were not handled by the application itself.
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
Use tools that are integrated during compilation to insert runtime error-checking mechanisms related to memory safety errors, such as AddressSanitizer (ASan) for C/C++ [7].
Effectiveness: Moderate
MITRE examples of the weakness in code.
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;
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);
}In the following code, the programmer assumes that the system always has a property named "cmd" defined. If an attacker can control the program's environment so that "cmd" is not defined, the program throws a NULL pointer exception when it attempts to call the trim() method.
Vulnerable example
String cmd = System.getProperty("cmd");
cmd = cmd.trim();This Android application has registered to handle a URL when sent an intent:
Vulnerable example
...
IntentFilter filter = new IntentFilter("com.example.URLHandler.openURL");
MyReceiver receiver = new MyReceiver();
registerReceiver(receiver, filter);
...
public class UrlHandlerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if("com.example.URLHandler.openURL".equals(intent.getAction())) {
String URL = intent.getStringExtra("URLToOpen");
int length = URL.length();
...
}
}
}The application assumes the URL will always be included in the intent. When the URL is not present, the call to getStringExtra() will return null, thus causing a null pointer exception when length() is called.
Consider the following example of a typical client server exchange. The HandleRequest function is intended to perform a request and use a defer to close the connection whenever the function returns.
Vulnerable example
func HandleRequest(client http.Client, request *http.Request) (*http.Response, error) {
response, err := client.Do(request)
defer response.Body.Close()
if err != nil {
return nil, err
}
...
}Real CVEs that MITRE cites as examples of this weakness.
Common questions about CWE-476.
Weakness data is sourced from the MITRE CWE catalog (v4.21). CVE associations are aggregated and kept current by RadicalNotion.AI.
Get an alert when a new CWE-476 CVE affects your products, with AI-written analysis and remediation steps.