]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nameserv: check that address returned from gethostbyname() is IPv4
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Oct 2014 11:50:52 +0000 (13:50 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 23 Oct 2014 13:06:00 +0000 (15:06 +0200)
Also, always return failure with -6.

nameserv.c

index f55ea3ce8a0f10ba18b82388f2a643e1c5e72c71..8134342e9f9b366c87a1bddbe7c4241ac49574d4 100644 (file)
@@ -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;