CWE-476: NULL Pointer Dereference (Base)

Description: A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit.

Extended Description: NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.


Alternate Terms: ::TERM:NPD::TERM:null deref::TERM:nil pointer dereference:DESCRIPTION:used for access of nil in Go programs::

Applicable Platforms: ::LANGUAGE NAME:C:LANGUAGE PREVALENCE:Undetermined::LANGUAGE NAME:C++:LANGUAGE PREVALENCE:Undetermined::LANGUAGE NAME:Java:LANGUAGE PREVALENCE:Undetermined::LANGUAGE NAME:C#:LANGUAGE PREVALENCE:Undetermined::LANGUAGE NAME:Go:LANGUAGE PREVALENCE:Undetermined::

Modes of Introduction: ::PHASE:Implementation::



Common Consequences: ::SCOPE:Availability:IMPACT:DoS: Crash, Exit, or Restart:NOTE: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.::SCOPE:Integrity:SCOPE:Confidentiality:SCOPE:Availability:IMPACT:Execute Unauthorized Code or Commands:IMPACT:Read Memory:IMPACT:Modify Memory:NOTE: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.::

Detection Methods: ::METHOD:Automated Dynamic Analysis:DESCRIPTION: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::METHOD:Manual Dynamic Analysis:DESCRIPTION: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.::METHOD:Automated Static Analysis:DESCRIPTION: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::

Potential Mitigations: ::PHASE:Implementation:DESCRIPTION:If all pointers that could have been modified are sanity-checked previous to use, nearly all NULL pointer dereferences can be prevented.::PHASE:Requirements:DESCRIPTION:The choice could be made to use a language that is not susceptible to these issues.::PHASE:Implementation:DESCRIPTION:Check the results of all functions that return a value and verify that the value is non-null before acting upon it.:EFFECTIVENESS:Moderate::PHASE:Architecture and Design:DESCRIPTION: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.::PHASE:Implementation:DESCRIPTION:Explicitly initialize all your variables and other data stores, either during declaration or just before the first usage.::PHASE:Testing:DESCRIPTION:Use automated static analysis tools that target this type of weakness. Many modern techniques use data flow analysis to minimize the number of false positives. This is not a perfect solution, since 100% accuracy and coverage are not feasible.::

Observed Examples: ::REFERENCE:CVE-2005-3274:DESCRIPTION:race condition causes a table to be corrupted if a timer activates while it is being modified, leading to resultant NULL dereference; also involves locking.:LINK:https://www.cve.org/CVERecord?id=CVE-2005-3274::REFERENCE:CVE-2002-1912:DESCRIPTION:large number of packets leads to NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2002-1912::REFERENCE:CVE-2005-0772:DESCRIPTION:packet with invalid error status value triggers NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2005-0772::REFERENCE:CVE-2009-4895:DESCRIPTION:Chain: race condition for an argument value, possibly resulting in NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2009-4895::REFERENCE:CVE-2020-29652:DESCRIPTION:ssh component for Go allows clients to cause a denial of service (nil pointer dereference) against SSH servers.:LINK:https://www.cve.org/CVERecord?id=CVE-2020-29652::REFERENCE:CVE-2009-2692:DESCRIPTION:Chain: Use of an unimplemented network socket operation pointing to an uninitialized handler function (CWE-456) causes a crash because of a null pointer dereference (CWE-476).:LINK:https://www.cve.org/CVERecord?id=CVE-2009-2692::REFERENCE:CVE-2009-3547:DESCRIPTION:Chain: race condition (CWE-362) might allow resource to be released before operating on it, leading to NULL dereference (CWE-476):LINK:https://www.cve.org/CVERecord?id=CVE-2009-3547::REFERENCE:CVE-2009-3620:DESCRIPTION:Chain: some unprivileged ioctls do not verify that a structure has been initialized before invocation, leading to NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2009-3620::REFERENCE:CVE-2009-2698:DESCRIPTION:Chain: IP and UDP layers each track the same value with different mechanisms that can get out of sync, possibly resulting in a NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2009-2698::REFERENCE:CVE-2009-2692:DESCRIPTION:Chain: uninitialized function pointers can be dereferenced allowing code execution:LINK:https://www.cve.org/CVERecord?id=CVE-2009-2692::REFERENCE:CVE-2009-0949:DESCRIPTION:Chain: improper initialization of memory can lead to NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2009-0949::REFERENCE:CVE-2008-3597:DESCRIPTION:Chain: game server can access player data structures before initialization has happened leading to NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2008-3597::REFERENCE:CVE-2020-6078:DESCRIPTION: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):LINK:https://www.cve.org/CVERecord?id=CVE-2020-6078::REFERENCE:CVE-2008-0062:DESCRIPTION:Chain: a message having an unknown message type may cause a reference to uninitialized memory resulting in a null pointer dereference (CWE-476) or dangling pointer (CWE-825), possibly crashing the system or causing heap corruption.:LINK:https://www.cve.org/CVERecord?id=CVE-2008-0062::REFERENCE:CVE-2008-5183:DESCRIPTION:Chain: unchecked return value can lead to NULL dereference:LINK:https://www.cve.org/CVERecord?id=CVE-2008-5183::REFERENCE:CVE-2004-0079:DESCRIPTION:SSL software allows remote attackers to cause a denial of service (crash) via a crafted SSL/TLS handshake that triggers a null dereference.:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0079::REFERENCE:CVE-2004-0365:DESCRIPTION:Network monitor allows remote attackers to cause a denial of service (crash) via a malformed RADIUS packet that triggers a null dereference.:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0365::REFERENCE:CVE-2003-1013:DESCRIPTION:Network monitor allows remote attackers to cause a denial of service (crash) via a malformed Q.931, which triggers a null dereference.:LINK:https://www.cve.org/CVERecord?id=CVE-2003-1013::REFERENCE:CVE-2003-1000:DESCRIPTION:Chat client allows remote attackers to cause a denial of service (crash) via a passive DCC request with an invalid ID number, which causes a null dereference.:LINK:https://www.cve.org/CVERecord?id=CVE-2003-1000::REFERENCE:CVE-2004-0389:DESCRIPTION:Server allows remote attackers to cause a denial of service (crash) via malformed requests that trigger a null dereference.:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0389::REFERENCE:CVE-2004-0119:DESCRIPTION:OS allows remote attackers to cause a denial of service (crash from null dereference) or execute arbitrary code via a crafted request during authentication protocol selection.:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0119::REFERENCE:CVE-2004-0458:DESCRIPTION:Game allows remote attackers to cause a denial of service (server crash) via a missing argument, which triggers a null pointer dereference.:LINK:https://www.cve.org/CVERecord?id=CVE-2004-0458::REFERENCE:CVE-2002-0401:DESCRIPTION:Network monitor allows remote attackers to cause a denial of service (crash) or execute arbitrary code via malformed packets that cause a NULL pointer dereference.:LINK:https://www.cve.org/CVERecord?id=CVE-2002-0401::REFERENCE:CVE-2001-1559:DESCRIPTION:Chain: System call returns wrong value (CWE-393), leading to a resultant NULL dereference (CWE-476).:LINK:https://www.cve.org/CVERecord?id=CVE-2001-1559::