krb5/krb5 — pull request #13 by vdukhovni (2013-01-31 04:28:59+00:00)
Title: Fix faulty hostname canonicalization #if defined(COPY_FIRST_CANONNAME)

On Linux systems with an old GLIBC and also on AIX, the macro
COPY_FIRST_CANONNAME is defined src/util/support/fake-addrinfo.c.
With this macro defined, the ai_canonname field in the result of
getaddrinfo() was originally replaced by the first plausible FQDN
in h_aliases[] from gethostbyname(). The author's comment was:

/* ... (h_name == h_aliases[0] on all systems I've seen) ... */

Unfortunately, this is not only not documented, but in fact not true on
NetBSD 5, MacOSX Mountain Lion, Ubuntu Karmic, Debian 7.0 (wheezy), ...
(It is hard to image this was ever true on any platform, but perhaps
the author was unlucky enough to have found some.) On all the above,
the primary host name in h_name is NOT also listed in h_aliases[], which
contains only additional names.

The solution is to start with h_name and only then look at aliases,
stopping at the first name that is a plausible FQDN (contains a
'.').