Package: libc6
Version: 2.19-18+deb8u10
Severity: normal
Tags: upstream ipv6 patch

Dear Maintainer,

The behavior of the test program from 
https://bugzilla.redhat.com/show_bug.cgi?id=1416496
(titled "getaddrinfo() call returns wrong IPv6 address if nscd is used") when 
asked to
return the IPv6 address of my local system varies according to whether nscd is 
running.
I think that the configuration is reasonable but, when nscd is running, the 
program
fails to return any IPv6 address:

martind@swiftboat:~$ ~/download/getaddrinfo AF_INET6 swiftboat
Hints family=10
error in getaddrinfo: Name or service not known
martind@swiftboat:~$ 

However, when I stop nscd, a local IPv6 address is returned:

martind@swiftboat:~$ sudo /etc/init.d/nscd stop
[ ok ] Stopping nscd (via systemctl): nscd.service.
martind@swiftboat:~$ ~/download/getaddrinfo AF_INET6 swiftboat
Hints family=10
host=swiftboat, family=10 addr=fdca:f995:220a:8400:ec4:7aff:fe00:cf5c
host=swiftboat, family=10 addr=fdca:f995:220a:8400:ec4:7aff:fe00:cf5c
host=swiftboat, family=10 addr=fdca:f995:220a:8400:ec4:7aff:fe00:cf5c

martind@swiftboat:~$ 

The applicable line in /etc/nsswitch.conf is:

hosts:          files myhostname dns

I think this is the Debian base-files default as modified by the postinst from
libnss-myhostname, a recommendation of gnome-control-center, an (indirect)
dependency of task-gnome-desktop.

The only applicable line in /etc/hosts is:

127.0.1.1       swiftboat.us.dev.bluearc.com    swiftboat

I think this is as suggested by the FQDN section in:

https://manpages.debian.org/jessie/hostname/dnsdomainname.1.en.html

Such a line causes hostname --fqdn to return the desired result.
There is no IPv6 address in /etc/hosts, but the host has a dynamically
determined IPv6 address known to libnss-myhostname.

Looking at the interface between glibc and nscd, the client side of which
I think is in sysdeps/posix/getaddrinfo.c's gaih_inet(), where it calls
__nscd_getai, I don't think nscd gets told what address family flags the
application passed to glibc.  I think nscd does pay correct attention to
nsswitch.conf, perhaps in the no_more loop in nscd/aicache.c's addhstaiX(),
but (correctly) stops on the first provider that returns any result.
In the case of my configuration, that's "files".  The one result returned
there is IPv4, so is discarded by glibc's nscd client leaving no result
to be returned.

If I put "myhostname" before "files" in /etc/nsswitch.conf, then this test
works perfectly but hostname --fqdn returns an unqualified name.
If I put an IPv6 address in /etc/hosts, then this test works perfectly and
I still have a FQDN, but that's inconvenient for a host whose IPv6 address
is dynamic.

Perhaps it's unusual to ask for a IPv6 address specifically from getaddrinfo,
but that's a useful way to determine a local IPv6 endpoint.
For a minority-interest query like that, perhaps it would be acceptable to
forego the full performance benefit of nscd's caching?
I contrived the attached patch on this assumption and saw that it passes this
test.

Apologies for submitting a bug report on such an old version of the code.
I haven't tried to patch any other version but I do see the problem on
Wheezy and Stretch systems as well as Jessie ones.
I think the upstream source would behave the same, but I haven't
experimentally verified that.
Upstream's bug submission guide:

https://sourceware.org/glibc/wiki/FilingBugs

... requested that I submit the issue to Debian first.
I was happy to do that not least because I'm less confident about
upstream's recommended /etc/nsswitch.conf and /etc/hosts.


-- System Information:
Debian Release: 8.10
  APT prefers oldstable-updates
  APT policy: (990, 'oldstable-updates'), (990, 'oldstable'), (500, 
'oldoldstable-updates'), (500, 'oldoldstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 3.16.0-6-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8) (ignored: LC_ALL 
set to en_US.UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages libc6:amd64 depends on:
ii  libgcc1  1:4.9.2-10+deb8u1

libc6:amd64 recommends no packages.

Versions of packages libc6:amd64 suggests:
ii  debconf [debconf-2.0]  1.5.56+deb8u1
ii  glibc-doc              2.19-18+deb8u10
ii  locales                2.19-18+deb8u10

-- debconf-show failed
--- sysdeps/posix/getaddrinfo.c	2018-09-17 11:00:52.932314024 -0700
+++ /home/martind/tmp/D136297/getaddrinfo.c.after	2018-09-17 11:00:20.821731456 -0700
@@ -788,13 +788,14 @@
 
 		  free (air);
 
-		  if (at->family == AF_UNSPEC)
+		  if (at->family == AF_UNSPEC && req->ai_family == AF_UNSPEC)
 		    {
 		      result = -EAI_NONAME;
 		      goto free_and_return;
 		    }
 
-		  goto process_list;
+		  if (at->family != AF_UNSPEC)
+		    goto process_list;
 		}
 	      else if (err == 0)
 		/* The database contains a negative entry.  */

Reply via email to