summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViktor Dukhovni <viktor@twosigma.com>2013-01-30 22:58:50 -0500
committerGreg Hudson <ghudson@mit.edu>2013-01-31 02:48:51 -0500
commit8924d0d333248e7ea1073affdf48eaafc1909d97 (patch)
treeceff2a3713c2fdfb7671ef091ebbba54c9e65a3b
parentcba077afd0a3c133c52cc25c84da62205ba61013 (diff)
downloadkrb5-8924d0d333248e7ea1073affdf48eaafc1909d97.tar.gz
krb5-8924d0d333248e7ea1073affdf48eaafc1909d97.tar.xz
krb5-8924d0d333248e7ea1073affdf48eaafc1909d97.zip
Fix COPY_FIRST_CANONNAME hostent search
In fake-addrinfo.c, the COPY_FIRST_CANONNAME logic erroneously assumes that h_name is the same as h_aliases[0]. Look at h_name before h_aliases for an FQDN, since h_name is normally the forward-canonicalized name and h_aliases are not. [ghudson@mit.edu: rewrote commit message] ticket: 7556 (new)
-rw-r--r--src/util/support/fake-addrinfo.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/util/support/fake-addrinfo.c b/src/util/support/fake-addrinfo.c
index 4efecd540f..2129758c07 100644
--- a/src/util/support/fake-addrinfo.c
+++ b/src/util/support/fake-addrinfo.c
@@ -1242,19 +1242,19 @@ getaddrinfo (const char *name, const char *serv, const struct addrinfo *hint,
ai->ai_canonname = 0;
name2 = ai->ai_canonname ? ai->ai_canonname : name;
} else {
- /* Sometimes gethostbyname will be directed to /etc/hosts
- first, and sometimes that file will have entries with
- the unqualified name first. So take the first entry
- that looks like it could be a FQDN. */
- for (i = 0; hp->h_aliases[i]; i++) {
- if (strchr(hp->h_aliases[i], '.') != 0) {
- name2 = hp->h_aliases[i];
+ /*
+ * Sometimes gethostbyname will be directed to /etc/hosts
+ * first, and sometimes that file will have entries with
+ * the unqualified name first. So take the first entry
+ * that looks like it could be a FQDN. Starting with h_name
+ * and then all the aliases.
+ */
+ for (i = 0, name2 = hp->h_name; name2; i++) {
+ if (strchr(name2, '.') != 0)
break;
- }
+ name2 = hp->h_aliases[i];
}
- /* Give up, just use the first name (h_name ==
- h_aliases[0] on all systems I've seen). */
- if (hp->h_aliases[i] == 0)
+ if (name2 == 0)
name2 = hp->h_name;
}