结构: Simple
Abstraction: Base
状态: Stable
被利用可能性: Medium
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.
NULL pointer dereference issues can occur through a number of flaws, including race conditions, and simple programming omissions.
cwe_Nature: ChildOf cwe_CWE_ID: 710 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: ChildOf cwe_CWE_ID: 754 cwe_View_ID: 1000
cwe_Nature: ChildOf cwe_CWE_ID: 754 cwe_View_ID: 1003 cwe_Ordinal: Primary
Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C#', 'cwe_Prevalence': 'Undetermined'}]
范围 | 影响 | 注释 |
---|---|---|
Availability | DoS: Crash, Exit, or Restart | 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. |
['Integrity', 'Confidentiality', 'Availability'] | Execute Unauthorized Code or Commands | In very rare circumstances and environments, code execution is possible. |
策略:
If all pointers that could have been modified are sanity-checked previous to use, nearly all NULL pointer dereferences can be prevented.
策略:
The choice could be made to use a 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.
策略:
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 your variables and other data stores, either during declaration or just before the first usage.
策略:
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.
While there are no complete fixes aside from conscientious programming, the following steps will go a long way to ensure that NULL pointer dereferences do not occur.
good
If you are working with a multithreaded or otherwise asynchronous environment, ensure that proper locking APIs are used to lock before the if statement; and unlock when it has finished.
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 C
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 would then occur in the call to strcpy().
Note that this example is also vulnerable to a buffer overflow (see CWE-119).
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.
bad Java
This application has registered to handle a URL when sent an intent:
bad Java
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.
标识 | 说明 | 链接 |
---|---|---|
CVE-2005-3274 | 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. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-3274 |
CVE-2002-1912 | large number of packets leads to NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-1912 |
CVE-2005-0772 | packet with invalid error status value triggers NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2005-0772 |
CVE-2009-4895 | chain: race condition for an argument value, possibly resulting in NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-4895 |
CVE-2009-3547 | chain: race condition might allow resource to be released before operating on it, leading to NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3547 |
CVE-2009-3620 | chain: some unprivileged ioctls do not verify that a structure has been initialized before invocation, leading to NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-3620 |
CVE-2009-2698 | 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 | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2698 |
CVE-2009-2692 | chain: uninitialized function pointers can be dereferenced allowing code execution | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-2692 |
CVE-2009-0949 | chain: improper initialization of memory can lead to NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2009-0949 |
CVE-2008-3597 | chain: game server can access player data structures before initialization has happened leading to NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-3597 |
CVE-2008-5183 | chain: unchecked return value can lead to NULL dereference | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2008-5183 |
CVE-2004-0079 | SSL software allows remote attackers to cause a denial of service (crash) via a crafted SSL/TLS handshake that triggers a null dereference. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-0079 |
CVE-2004-0365 | Network monitor allows remote attackers to cause a denial of service (crash) via a malformed RADIUS packet that triggers a null dereference. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-0365 |
CVE-2003-1013 | Network monitor allows remote attackers to cause a denial of service (crash) via a malformed Q.931, which triggers a null dereference. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-1013 |
CVE-2003-1000 | 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. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-1000 |
CVE-2004-0389 | Server allows remote attackers to cause a denial of service (crash) via malformed requests that trigger a null dereference. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-0389 |
CVE-2004-0119 | 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. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-0119 |
CVE-2004-0458 | Game allows remote attackers to cause a denial of service (server crash) via a missing argument, which triggers a null pointer dereference. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2004-0458 |
CVE-2002-0401 | 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. | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2002-0401 |
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
7 Pernicious Kingdoms | Null Dereference | ||
CLASP | Null-pointer dereference | ||
PLOVER | Null Dereference (Null Pointer Dereference) | ||
OWASP Top Ten 2004 | A9 | CWE More Specific | Denial of Service |
CERT C Secure Coding | EXP34-C | Exact | Do not dereference null pointers |
Software Fault Patterns | SFP7 | Faulty Pointer Use |