CWE-690¶
Unchecked Return Value to NULL Pointer Dereference. [Improper-Check-Or-Handling-Of-Exceptional-Conditions]
Required inputs: IR
Demonstrative Examples
Example 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).
Example Language:Java (Unsupported language for documentation only)
String username = getUserName();
if (username.equals(ADMIN_USER)) {
...
}
Example 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.
Example Language:C
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);
}
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().
Note that this code is also vulnerable to a buffer overflow (CWE-119).
Excerpts from CWE [https://cwe.mitre.org], Copyright (C) 2006-2026, the MITRE Corporation. See section 9.4. "3rd-Party Licenses" in the documentation for full details.Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
unchecked_dereference |
Unchecked dereference. |
None |
False |
Options¶
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
allow_non_null_comparison¶
allow_non_null_comparison : bool = True
dereference_filter¶
dereference_filter
Filter predicate for dereferenced objects.Type: typing.Callable[[Direct_Object_Selection_Interface], bool] | None
Default:
functools.partial(<function pointer_return_filter at 0x7f6f18ee7910>, function_returns=set())
ignored_object_types¶
ignored_object_types : set[bauhaus.ir.LIR_Class_Name] = set()
null_check_macro¶
null_check_macro : bauhaus.analysis.config.MacroName = ''
NULL.
null_check_routines¶
null_check_routines : set[bauhaus.analysis.config.QualifiedName] = set()
routines_returning_valid_pointers¶
routines_returning_valid_pointers : set[bauhaus.analysis.config.QualifiedName] = {'std::make_shared', 'std::make_unique'}
types_ignored_by_qualified_name¶
types_ignored_by_qualified_name : set[bauhaus.analysis.config.QualifiedName] = set()