Bug 798627 - gethostbyname() can return duplicate addresses
gethostbyname() can return duplicate addresses
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: glibc (Show other bugs)
All Linux
unspecified Severity low
: rc
: ---
Assigned To: Jeff Law
Depends On:
  Show dependency treegraph
Reported: 2012-02-29 07:26 EST by Jonathan Peatfield
Modified: 2016-11-24 10:38 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2012-03-01 01:25:02 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Jonathan Peatfield 2012-02-29 07:26:43 EST
Description of problem:

Since upgrading to glibc-2.5-65.el5_7.3 we noticed that gethostbyname() can now return duplicate addresses - if the name appears in /etc/hosts multiple times.

Machines running with glibc-2.5-58.el5_6.4 do not show this behaviour.

I've not tested glibc-2.5-81 yet but the announcement https://rhn.redhat.com/errata/RHBA-2012-0260.html does not mention anything obviously related.

Note in the test setup we have nsswitch set to look in /etc/hosts first and host.conf has multi set to on, but so do the systems with the previous glibc which do no show the new behaviour.

Running with/without nscd doesn't affect this other than that it caches the results.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:

Here is my test procedure.

I wrote a trivial test script ~/scripts/gethostbyname.pl :

#! /usr/bin/perl
use Socket;
foreach $i (@ARGV) {
    printf "%-25s %s\n", $name, $i;
    foreach $ad (@addrs) {
        print " ".inet_ntoa($ad)."\n";

On a machine running the newer glibc:

# grep multi /etc/host.conf
multi on
# grep '^host' /etc/nsswitch.conf
hosts:      files dns
# service nscd stop
Stopping nscd:                                  [  OK  ]
# grep beast /etc/hosts
# ~jp107/scripts/gethostbyname.pl beast
# echo " beast" >> /etc/hosts
# grep beast /etc/hosts| wc -l
# ~jp107/scripts/gethostbyname.pl beast
beast                     beast
# echo " beast" >> /etc/hosts
# grep beast /etc/hosts| wc -l
# ~jp107/scripts/gethostbyname.pl beast
beast                     beast
# echo " beast" >> /etc/hosts
# grep beast /etc/hosts| wc -l
# ~jp107/scripts/gethostbyname.pl beast
beast                     beast

Actual results:

duplicate (idential) addresses returned

Expected results:

each unique address returned only once.

Additional info:

The 'old' glibc behaviour is what we also get on Solaris.  It is possible that gethostbyname() was always intended to return the address multiple times, and the previous behaviour was a (very longstanding) bug.

We originally noticed this because a script we use to generate /etc/host sticks some names in twice.  Apache got confused if a "listen name:port" where gethostbyname(name) returns the same address multiple times - it tries to bind to the same address/port multiple times which fails (and the apache error message doesn't make it clear what is going wrong, but that isn't glibc's fault)...

We have corrected our script to avoid those duplicates, but the change of behaviour in glibc might affect others.
Comment 1 Jonathan Peatfield 2012-02-29 07:31:14 EST
I believe that the 'new' behaviour is also present in the latest glibc in EL6.2, but I have not tested that myself.

Sorry I forgot to mention that we are actually running on Scientific Linux 5.7 but it is hard to see that this won't also affect RHEL customers since the glibc would be built from the same srpms.
Comment 2 Jeff Law 2012-03-01 01:25:02 EST
I've been unable to recreate your desired behavior, even after installing a fresh version of Red Hat Enterprise Linux 5.6 with glibc-2.5-58.el5_6.4 which reportedly has the desired behaviour.

The returning multiple entries, including duplicates has been the intended behaviour when /etc/host.conf specifies "multi on" since 2000 (glibc-2.1.91).  This pre-dates Red Hat Enterprise Linux 3.0. 

There have been a couple bugs where glibc was not producing the intended behaviour; one occurred when using nscd, the other using the getaddrinfo routine from glibc.  Both were fixed in glibc-2.5-65.

Given the behaviour you're seeing in the intended behaviour when /etc/host.conf specifies multi on, I'm closing this as NOTABUG.

If you have further questions, feel free to add them to this bug report.  I'll get notified if you add any comments.

Note You need to log in before you can comment on or make changes to this bug.