From: Miroslav Lichvar Date: Tue, 21 Oct 2014 11:50:52 +0000 (+0200) Subject: nameserv: check that address returned from gethostbyname() is IPv4 X-Git-Tag: 2.0-pre1~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=699680807da4f0628d72e345c6e67f82e2baef58;p=thirdparty%2Fchrony.git nameserv: check that address returned from gethostbyname() is IPv4 Also, always return failure with -6. --- diff --git a/nameserv.c b/nameserv.c index f55ea3ce..8134342e 100644 --- a/nameserv.c +++ b/nameserv.c @@ -88,12 +88,18 @@ DNS_Name2IPAddress(const char *name, IPAddr *addr) #else struct hostent *host; + if (address_family != IPADDR_UNSPEC && address_family != IPADDR_INET4) + return DNS_Failure; + host = gethostbyname(name); if (host == NULL) { if (h_errno == TRY_AGAIN) return DNS_TryAgain; } else { + if (host->h_addrtype != AF_INET || !host->h_addr_list[0]) + return DNS_Failure; + addr->family = IPADDR_INET4; addr->addr.in4 = ntohl(*(uint32_t *)host->h_addr_list[0]); return DNS_Success;