Bug 14212 - getaddrinfo() with multiple results from /etc/hosts and AF_INET6 in hints fails when /etc/hosts.conf:multi=off
Summary: getaddrinfo() with multiple results from /etc/hosts and AF_INET6 in hints fai...
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.15
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-09 05:15 IST by Mike Frysinger
Modified: 2014-09-27 05:51 IST (History)
2 users (show)

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


Attachments
getaddrinfo test (386 bytes, text/plain)
2012-06-09 05:15 IST, Mike Frysinger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Frysinger 2012-06-09 05:15:17 IST
Created attachment 6444 [details]
getaddrinfo test

i have these /etc settings:

$ cat /etc/hosts
127.0.0.1   localhost
::1         localhost

$ cat /etc/host.conf 
order hosts, bind
multi off

trying to do getaddrinfo("localhost") when hints is just set to ai_family=AF_INET6 fails with EAI_NODATA when it should have returned ::1

if i change multi on, then i get back ::1 as expected

if i also use ai_flags=AI_V4MAPPED, then multi off gives me ::ffff:127.0.0.1 -- which is correct, just pointing out that it seems to be matching the first result and then aborting because the hints didn't line up

see attached code:
$ gcc getaddrinfo.c && ./a.out localhost
Comment 1 Siddhesh Poyarekar 2013-04-15 13:11:27 IST
I cannot reproduce this with latest master.

$ cat /etc/hosts
127.0.0.1   localhost
::1         localhost

$ cat /etc/host.conf
order hosts, bind
multi off

$ ./a.out localhost
this is an IPv6 result
this is an IPv6 result
this is an IPv6 result
Comment 2 Alexandre Oliva 2014-09-27 05:51:00 IST
This was fixed, apparently by accident, with the patch for bug 14505, commit 8479f23aa1.  It disabled the use of the nss gethostbyname4 interface for non-AF_UNSPEC queries.  Without the patch, we'd use gethostbyname4, get only the
IPv4 address from the hosts plugin (because multi is off, and gethostbyname4 doesn't know what address family we're looking for), and discard that address as unsuitable.  With the patch, we use gethostbyname2 to look up IPv6 addresses only.  It doesn't perform V4MAPPED conversions, for the hconf flag that would do so is explicitly cleared by getaddrinfo, that would look up IPv4 addresses separately afterwards in case of no IPv6 matches.