Bug 13760 - [PATCH] Fix dns lookup for AF_UNSPEC when response for T_A exceeds buffer size
Summary: [PATCH] Fix dns lookup for AF_UNSPEC when response for T_A exceeds buffer size
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-27 05:45 UTC by Siddhesh Poyarekar
Modified: 2014-06-26 14:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Siddhesh Poyarekar 2012-02-27 05:45:16 UTC
When a dns lookup is made for a host that returns a large number of
results for A (over 28 records in my test) and a finite number for
AAAA, getaddrinfo ends up returning only the AAAA records.

I have posted a patch on libc-alpha to fix this:

http://sourceware.org/ml/libc-alpha/2012-02/msg00502.html

An example DNS zone file that should trigger this problem:

$TTL    86400 ; 24 hours could have been written as 24h or 1d
$ORIGIN foo.net.
@  1D  IN        SOA ns1.foo.net.    hostmaster.foo.net. (
                              2002022401 ; serial
                              3H ; refresh
                              15 ; retry
                              1w ; expire
                              3h ; minimum
                             )
       IN  NS     ns1.foo.net. ; in the domain
; server host definitions
ns1    IN  A      192.168.0.1  ;name server definition

; non server domain hosts
ad IN A 1.0.0.1
ad IN A 1.0.0.2
ad IN A 1.0.0.3
ad IN A 1.0.0.4
ad IN A 1.0.0.5
ad IN A 1.0.0.6
ad IN A 1.0.0.7
ad IN A 1.0.0.8
ad IN A 1.0.0.9
ad IN A 1.0.1.1
ad IN A 1.0.1.2
ad IN A 1.0.1.3
ad IN A 1.0.1.4
ad IN A 1.0.1.5
ad IN A 1.0.1.6
ad IN A 1.0.1.7
ad IN A 1.0.1.8
ad IN A 1.0.1.9
ad IN A 1.0.2.1
ad IN A 1.0.2.2
ad IN A 1.0.2.3
ad IN A 1.0.2.4
ad IN A 1.0.2.5
ad IN A 1.0.2.6
ad IN A 1.0.2.7
ad IN A 1.0.2.8
ad IN A 1.0.2.9
ad IN A 1.0.3.1
ad IN AAAA 2002:2003:dead::beef:f00d

A simple lookup program returns just the IPv6 address and not the ipv4 addresses:

#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
int main(void)
{
  struct addrinfo *result;
  struct addrinfo *res;
  int error;
  const char *domain = "ad.foo.net";
  error = getaddrinfo(domain, NULL, NULL, &result);
  if (error != 0)
    {
      fprintf(stderr, "error in getaddrinfo: %s\n", gaistrerror(error));
      return 1;
    }
  /* print the domain name */
  printf("%s:\n", domain);
  /* loop over all returned results and print the addresses */
  for (res = result; res != NULL; res = res->ainext)
    {
      void *addr;
      char address[64] = "";
      if (res->aifamily == AFINET) {
    addr = &((struct sockaddrin *)(res->aiaddr))->sinaddr;
      } else if (res->aifamily == AFINET6) {
    addr = &((struct sockaddrin6 *)(res->aiaddr))->sin6addr;
      }
      inetntop(res->aiaddr->safamily, addr, address, 64);
      printf("  %s\n", address);
    }
  freeaddrinfo(result);
  return EXITSUCCESS;
}

$ ./a.out
ad.foo.net:
  2002:2003:dead::beef:f00d
  2002:2003:dead::beef:f00d
  2002:2003:dead::beef:f00d
Comment 1 Siddhesh Poyarekar 2012-03-30 07:32:21 UTC
Fixed in master with 86ae07a8c9e8e26806f7b8dedf57e7b14a308c69.