Bug 10540

Summary: getaddrinfo() fails if /etc/hosts is missing, instead of falling through to nss_dns
Product: glibc Reporter: Steve Langasek <vorlon>
Component: networkAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: 2.10   
Target Milestone: ---   
Host: x86_64-linux-gnu Target: x86_64-linux-gnu
Build: x86_64-linux-gnu Last reconfirmed:
Attachments: test case
patch to nss_files fixing getaddrinfo when /etc/hosts is absent

Description Steve Langasek 2009-08-20 12:30:35 UTC
glibc 2.10 introduces a regression in getaddrinfo(); with a standard nsswitch.conf:

$ grep host /etc/nsswitch.conf 
hosts:          files dns
$

and no /etc/hosts file on the system (which is legitimate; e.g., in a chroot):

$ cat /etc/hosts
cat: /etc/hosts: No such file or directory
$

all calls to getaddrinfo() will fail, short-circuited by an nss_files failure
before invoking nss_dns.

Trivial test case, patch to follow.
Comment 1 Steve Langasek 2009-08-20 12:32:19 UTC
Created attachment 4142 [details]
test case
Comment 2 Steve Langasek 2009-08-20 12:34:32 UTC
Created attachment 4143 [details]
patch to nss_files fixing getaddrinfo when /etc/hosts is absent
Comment 3 Ulrich Drepper 2009-10-30 05:05:33 UTC
I applied the patch.
Comment 4 Michel Hermier 2009-12-19 13:28:52 UTC
Seems the fix is incorrect, on 2.11 I get:

bash-4.0# gcc bug-408901.c
bash-4.0# ./a.out www.redhat.com
www.redhat.com -5
bash-4.0# touch /etc/hosts
bash-4.0# ./a.out www.redhat.com
www.redhat.com 0

It seems that returning NO_DATA (in the patch) stops the host search
prematurely. Instead returning HOST_NOT_FOUND fix the issue, and sounds more
logical.
Comment 5 Andreas Schwab 2013-02-04 15:49:34 UTC
Appears to be working fine with 2.17.