1516
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).
Observed Examples
Reference Description
CVE-2008-1052 Large Content-Length value leads to NULL pointer dereference when malloc
fails.
https://www.cve.org/CVERecord?id=CVE-2008-1052
CVE-2006-6227 Large message length field leads to NULL pointer dereference when malloc
fails.
https://www.cve.org/CVERecord?id=CVE-2006-6227
CVE-2006-2555 Parsing routine encounters NULL dereference when input is missing a colon
separator.
https://www.cve.org/CVERecord?id=CVE-2006-2555
CVE-2003-1054 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.
https://www.cve.org/CVERecord?id=CVE-2003-1054
CVE-2008-5183 chain: unchecked return value can lead to NULL dereference
https://www.cve.org/CVERecord?id=CVE-2008-5183
MemberOf Relationships
This MemberOf relationships table shows additional CWE Catgeories and Views that reference this
weakness as a member. This information is often useful in understanding where a weakness fits
within the context of external information sources.
Nature Type ID Name Page
MemberOf 851 The CERT Oracle Secure Coding Standard for Java
(2011) Chapter 8 - Exceptional Behavior (ERR)
844 2365
MemberOf 876 CERT C++ Secure Coding Section 08 - Memory
Management (MEM)
868 2376
MemberOf 1157 SEI CERT C Coding Standard - Guidelines 03.
Expressions (EXP)
1154 2455
MemberOf 1181 SEI CERT Perl Coding Standard - Guidelines 03.
Expressions (EXP)
1178 2466
MemberOf 1399 Comprehensive Categorization: Memory Safety 1400 2525
Taxonomy Mappings
Mapped Taxonomy Name Node ID Fit Mapped Node Name
CERT C Secure Coding EXP34-C CWE More Specific Do not dereference null pointers
The CERT Oracle Secure
Coding Standard for Java
(2011)
ERR08-J Do not catch NullPointerException or
any of its ancestors
CWE Version 4.14
CWE-691: Insufficient Control Flow Management
CWE-691: Insufficient Control Flow Management