Bug 10540 - getaddrinfo() fails if /etc/hosts is missing, instead of falling through to nss_dns
Summary: getaddrinfo() fails if /etc/hosts is missing, instead of falling through to n...
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: network (show other bugs)
Version: 2.10
: P2 normal
Target Milestone: ---
Assignee: Ulrich Drepper
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-20 12:30 UTC by Steve Langasek
Modified: 2014-07-01 07:04 UTC (History)
1 user (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Last reconfirmed:
fweimer: security-


Attachments
test case (168 bytes, text/x-csrc)
2009-08-20 12:32 UTC, Steve Langasek
Details
patch to nss_files fixing getaddrinfo when /etc/hosts is absent (288 bytes, patch)
2009-08-20 12:34 UTC, Steve Langasek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.