mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 09:05:07 -05:00
nameserv: check that address returned from gethostbyname() is IPv4
Also, always return failure with -6.
This commit is contained in:
@@ -88,12 +88,18 @@ DNS_Name2IPAddress(const char *name, IPAddr *addr)
|
|||||||
#else
|
#else
|
||||||
struct hostent *host;
|
struct hostent *host;
|
||||||
|
|
||||||
|
if (address_family != IPADDR_UNSPEC && address_family != IPADDR_INET4)
|
||||||
|
return DNS_Failure;
|
||||||
|
|
||||||
host = gethostbyname(name);
|
host = gethostbyname(name);
|
||||||
|
|
||||||
if (host == NULL) {
|
if (host == NULL) {
|
||||||
if (h_errno == TRY_AGAIN)
|
if (h_errno == TRY_AGAIN)
|
||||||
return DNS_TryAgain;
|
return DNS_TryAgain;
|
||||||
} else {
|
} else {
|
||||||
|
if (host->h_addrtype != AF_INET || !host->h_addr_list[0])
|
||||||
|
return DNS_Failure;
|
||||||
|
|
||||||
addr->family = IPADDR_INET4;
|
addr->family = IPADDR_INET4;
|
||||||
addr->addr.in4 = ntohl(*(uint32_t *)host->h_addr_list[0]);
|
addr->addr.in4 = ntohl(*(uint32_t *)host->h_addr_list[0]);
|
||||||
return DNS_Success;
|
return DNS_Success;
|
||||||
|
|||||||
Reference in New Issue
Block a user